Interface ReadOnlyList<E>
- Type Parameters:
E- the element type
- All Superinterfaces:
Iterable<E>,ReadOnlyCollection<E>,ReadOnlySequencedCollection<E>
- All Known Subinterfaces:
ImmutableList<E>
- All Known Implementing Classes:
AbstractReadOnlyList,MutableListFacade,MutableVectorList,ReadOnlyListFacade,VectorList
Note: To compare a ReadOnlyList to a List, you must either
wrap the ReadOnlyList into a List using ListFacade,
or wrap the List into a ReadOnlyList using ReadOnlyListFacade.
This interface does not guarantee 'read-only', it actually guarantees 'readable'. We use the prefix 'ReadOnly' because this is the naming convention in JavaFX for interfaces that provide read methods but no write methods.
-
Method Summary
Modifier and TypeMethodDescriptionasList()Wraps this list in the List interface - without copying.booleanCompares the specified object with this list for equality.get(int index) Returns the element at the specified position in this list.default EgetFirst()Gets the first element of the list.default EgetLast()Gets the last element of the list.default EgetLast(int index) Returns the element at the specified position in this list, counted from the last element of the list.inthashCode()Returns the hash code value for this list.default intReturns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.iterator()Returns an iterator over elements of typeE.static <E> intiteratorToHashCode(Iterator<E> iterator) Returns the hash code of the provided iterable, assuming that the iterator is from a list.default intReturns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.static <E> booleanlistEquals(ReadOnlyList<E> list, @Nullable Object o) Compares the given list with the given object for equality.default ListIterator<E> Returns a list iterator over elements of typeE.default ListIterator<E> listIterator(int index) Returns a list iterator over elements of typeEstarting at the specified index.default @Nullable EPeeks the first element of the list.default @Nullable EpeekLast()Peeks the last element of the list.readOnlySubList(int fromIndex, int toIndex) Returns a view of the portion of this list between the specified *fromIndex, inclusive, andtoIndex, exclusive.default Spliterator<E> Returns a spliterator over elements of typeE.Methods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyCollection
characteristics, contains, containsAll, isEmpty, size, stream, toArray, toArrayMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySequencedCollection
asCollection, readOnlyReversed
-
Method Details
-
get
Returns the element at the specified position in this list.- Parameters:
index- the index of the element- Returns:
- the element
- Throws:
IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size())
-
getLast
Returns the element at the specified position in this list, counted from the last element of the list.- Parameters:
index- the index of the element, counted from the last element.- Returns:
- the element
- Throws:
IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size())
-
getFirst
Gets the first element of the list.- Specified by:
getFirstin interfaceReadOnlySequencedCollection<E>- Returns:
- the first element
- Throws:
NoSuchElementException- if the list is empty
-
getLast
Gets the last element of the list.- Specified by:
getLastin interfaceReadOnlySequencedCollection<E>- Returns:
- the last element
- Throws:
NoSuchElementException- if the list is empty
-
peekFirst
Peeks the first element of the list.- Returns:
- the first element or null if the list is empty
-
peekLast
Peeks the last element of the list.- Returns:
- the last element or null if the list is empty
-
iterator
Returns an iterator over elements of typeE. -
spliterator
Returns a spliterator over elements of typeE.- Specified by:
spliteratorin interfaceIterable<E>- Returns:
- an iterator.
-
listIterator
Returns a list iterator over elements of typeE.- Returns:
- a list iterator.
-
listIterator
Returns a list iterator over elements of typeEstarting at the specified index.- Parameters:
index- the start index- Returns:
- a list iterator.
-
asList
Wraps this list in the List interface - without copying.- Returns:
- the wrapped list
-
readOnlySubList
Returns a view of the portion of this list between the specified *fromIndex, inclusive, andtoIndex, exclusive.- Parameters:
fromIndex- the from indextoIndex- the to index (exclusive)- Returns:
- the sub list
-
indexOf
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.- Parameters:
o- an element- Returns:
- the index of the element or -1
-
lastIndexOf
Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.- Parameters:
o- an element- Returns:
- the index of the element or -1
-
listEquals
Compares the given list with the given object for equality.Returns
trueif the given object is also a read-only list and the two lists contain the same elements in the same sequence.- Type Parameters:
E- the element type of the list- Parameters:
list- a listo- an object- Returns:
trueif the object is equal to this list
-
iteratorToHashCode
Returns the hash code of the provided iterable, assuming that the iterator is from a list.- Parameters:
iterator- an iterator over a list- Returns:
- the ordered sum of the hash codes of the elements in the list
- See Also:
-
equals
Compares the specified object with this list for equality.Returns
trueif the given object is also a read-only list and the two lists contain the same elements in the same sequence.Implementations of this method should use
listEquals(org.jhotdraw8.icollection.readonly.ReadOnlyList<E>, java.lang.Object). -
hashCode
int hashCode()Returns the hash code value for this list. The hash code is the result of the calculation described inList.hashCode().Implementations of this method should use
iteratorToHashCode(java.util.Iterator<E>).
-