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

public interface ReadOnlyList<E> extends ReadOnlySequencedCollection<E>
A read-only interface to a set. A set is a collection that contains no duplicate elements.

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 Type
    Method
    Description
    default List<E>
    Wraps this list in the List interface - without copying.
    boolean
    equals(@Nullable Object o)
    Compares the specified object with this list for equality.
    get(int index)
    Returns the element at the specified position in this list.
    default E
    Gets the first element of the list.
    default E
    Gets the last element of the list.
    default E
    getLast(int index)
    Returns the element at the specified position in this list, counted from the last element of the list.
    int
    Returns the hash code value for this list.
    default int
    Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
    default Iterator<E>
    Returns an iterator over elements of type E.
    static <E> int
    Returns the hash code of the provided iterable, assuming that the iterator is from a list.
    default int
    Returns 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> boolean
    listEquals(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 type E.
    default ListIterator<E>
    listIterator(int index)
    Returns a list iterator over elements of type E starting at the specified index.
    default @Nullable E
    Peeks the first element of the list.
    default @Nullable E
    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, and toIndex, exclusive.
    default Spliterator<E>
    Returns a spliterator over elements of type E.

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyCollection

    characteristics, contains, containsAll, isEmpty, size, stream, toArray, toArray

    Methods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySequencedCollection

    asCollection, readOnlyReversed
  • Method Details

    • get

      E get(int index)
      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

      default E getLast(int index)
      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

      default E getFirst()
      Gets the first element of the list.
      Specified by:
      getFirst in interface ReadOnlySequencedCollection<E>
      Returns:
      the first element
      Throws:
      NoSuchElementException - if the list is empty
    • getLast

      default E getLast()
      Gets the last element of the list.
      Specified by:
      getLast in interface ReadOnlySequencedCollection<E>
      Returns:
      the last element
      Throws:
      NoSuchElementException - if the list is empty
    • peekFirst

      default @Nullable E peekFirst()
      Peeks the first element of the list.
      Returns:
      the first element or null if the list is empty
    • peekLast

      default @Nullable E peekLast()
      Peeks the last element of the list.
      Returns:
      the last element or null if the list is empty
    • iterator

      default Iterator<E> iterator()
      Returns an iterator over elements of type E.
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface ReadOnlyCollection<E>
      Returns:
      an iterator.
    • spliterator

      default Spliterator<E> spliterator()
      Returns a spliterator over elements of type E.
      Specified by:
      spliterator in interface Iterable<E>
      Returns:
      an iterator.
    • listIterator

      default ListIterator<E> listIterator()
      Returns a list iterator over elements of type E.
      Returns:
      a list iterator.
    • listIterator

      default ListIterator<E> listIterator(int index)
      Returns a list iterator over elements of type E starting at the specified index.
      Parameters:
      index - the start index
      Returns:
      a list iterator.
    • asList

      default List<E> asList()
      Wraps this list in the List interface - without copying.
      Returns:
      the wrapped list
    • readOnlySubList

      ReadOnlyList<E> readOnlySubList(int fromIndex, int toIndex)
      Returns a view of the portion of this list between the specified * fromIndex, inclusive, and toIndex, exclusive.
      Parameters:
      fromIndex - the from index
      toIndex - the to index (exclusive)
      Returns:
      the sub list
    • indexOf

      default int indexOf(Object o)
      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

      default int lastIndexOf(Object o)
      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

      static <E> boolean listEquals(ReadOnlyList<E> list, @Nullable Object o)
      Compares the given list with the given object for equality.

      Returns true if 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 list
      o - an object
      Returns:
      true if the object is equal to this list
    • iteratorToHashCode

      static <E> int iteratorToHashCode(Iterator<E> iterator)
      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

      boolean equals(@Nullable Object o)
      Compares the specified object with this list for equality.

      Returns true if 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).

      Overrides:
      equals in class Object
      Parameters:
      o - an object
      Returns:
      true if the object is equal to this list
    • hashCode

      int hashCode()
      Returns the hash code value for this list. The hash code is the result of the calculation described in List.hashCode().

      Implementations of this method should use iteratorToHashCode(java.util.Iterator<E>).

      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this set