Class ImmutableList<T>

  • Type Parameters:
    T - Type of elements in this list.
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<T>, Collection<T>, List<T>, Sequence<T>

    public final class ImmutableList<T>
    extends ReadOnlySequence<T>
    implements List<T>
    Unmodifiable implementation of the List interface.
    See Also:
    Serialized Form
    • Constructor Detail

      • ImmutableList

        public ImmutableList​(List<T> list)
    • Method Detail

      • get

        public T get​(int index)
        Description copied from interface: Sequence
        Retrieves the item at the given index.
        Specified by:
        get in interface Sequence<T>
        Parameters:
        index - The index of the item to retrieve.
        Returns:
        The item at this index in the sequence.
      • indexOf

        public int indexOf​(T item)
        Description copied from interface: Sequence
        Returns the index of an item in the sequence.
        Specified by:
        indexOf in interface Sequence<T>
        Parameters:
        item - The item to locate.
        Returns:
        The index of first occurrence of the item if it exists in the sequence; -1, otherwise.
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Collection
        Tests the emptiness of the collection.
        Specified by:
        isEmpty in interface Collection<T>
        Returns:
        true if the collection contains no elements; false, otherwise.
      • getLength

        public int getLength()
        Description copied from interface: List
        Returns the length of the list.
        Specified by:
        getLength in interface List<T>
        Specified by:
        getLength in interface Sequence<T>
        Returns:
        The number of items in the list, or -1 if the list's length is not known. In this case, the iterator must be used to retrieve the contents of the list.
      • getComparator

        public java.util.Comparator<T> getComparator()
        Description copied from interface: Collection
        Returns the collection's sort order.
        Specified by:
        getComparator in interface Collection<T>
        Returns:
        The comparator used to order elements in the collection, or null if the sort order is undefined.
        See Also:
        Collection.setComparator(Comparator)
      • setComparator

        @UnsupportedOperation
        public void setComparator​(java.util.Comparator<T> comparator)
        Description copied from interface: Collection
        Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.

        Calling this method more than once with the same comparator will re-sort the collection.

        Specified by:
        setComparator in interface Collection<T>
        Specified by:
        setComparator in interface List<T>
        Parameters:
        comparator - The comparator used to order elements in the collection, or null if the collection is unsorted.
        See Also:
        ListListener.comparatorChanged(List, Comparator)
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<T>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getListListeners

        public ListenerList<ListListener<T>> getListListeners()
        Get the list of listeners for this list.

        Not clear why this would be used, since the listener(s) would only be called on changes to the list, which can't happen on an immutable list.

        Specified by:
        getListListeners in interface List<T>
        Returns:
        The list listener list.