Interface ImmutableList<E>

Type Parameters:
E - the element type
All Superinterfaces:
ImmutableCollection<E>, ImmutableSequencedCollection<E>, Iterable<E>, ReadOnlyCollection<E>, ReadOnlyList<E>, ReadOnlySequencedCollection<E>
All Known Implementing Classes:
VectorList

public interface ImmutableList<E> extends ReadOnlyList<E>, ImmutableSequencedCollection<E>
An interface to an immutable list; the implementation guarantees that the state of the collection does not change.

An interface to an immutable list provides methods for creating a new immutable list with added or removed elements, without changing the original immutable list.

  • Method Details

    • empty

      <T> ImmutableList<T> empty()
      Returns a copy of this list that is empty.
      Specified by:
      empty in interface ImmutableCollection<E>
      Specified by:
      empty in interface ImmutableSequencedCollection<E>
      Type Parameters:
      T - the element type of the returned collection
      Returns:
      this list instance if it is already empty, or a different list instance that is empty.
    • addFirst

      ImmutableList<E> addFirst(@Nullable E element)
      Description copied from interface: ImmutableSequencedCollection
      Returns a copy of this collection that contains all elements of this collection and also the specified element as the first element in the iteration order.

      A collection may prevent that the same element can be added more than once.

      If the iteration order is based on an ordering relation of the elements, then the element is only the first in a sequence of elements with the same ordering relation; which is not necessarily the first in the total iteration order.

      Specified by:
      addFirst in interface ImmutableSequencedCollection<E>
      Parameters:
      element - an element
      Returns:
      this collection instance if it already contains the element as the first in the iteration order, or a different collection instance with the element added as the first in the iteration order
    • addLast

      ImmutableList<E> addLast(@Nullable E element)
      Description copied from interface: ImmutableSequencedCollection
      Returns a copy of this collection that contains all elements of this collection and also the specified element as the last element in the iteration order.

      A collection may prevent that the same element can be added more than once.

      If the iteration order is based on an ordering relation of the elements, then the element is only the last in a sequence of elements with the same ordering relation; which is not necessarily the last in the total iteration order.

      Specified by:
      addLast in interface ImmutableSequencedCollection<E>
      Parameters:
      element - an element
      Returns:
      this collection instance if it already contains the element as the last in the iteration order, or a different collection instance with the element added as the last in the iteration order
    • removeFirst

      default ImmutableList<E> removeFirst()
      Description copied from interface: ImmutableSequencedCollection
      Returns a copy of this set that contains all elements of this set except the first.
      Specified by:
      removeFirst in interface ImmutableSequencedCollection<E>
      Returns:
      a new set instance with the first element removed
    • removeLast

      default ImmutableList<E> removeLast()
      Description copied from interface: ImmutableSequencedCollection
      Returns a copy of this set that contains all elements of this set except the last.
      Specified by:
      removeLast in interface ImmutableSequencedCollection<E>
      Returns:
      a new set instance with the last element removed
    • add

      ImmutableList<E> add(E element)
      Returns a copy of this list that contains all elements of this list and the specified element appended to the end of the list.
      Specified by:
      add in interface ImmutableCollection<E>
      Specified by:
      add in interface ImmutableSequencedCollection<E>
      Parameters:
      element - an element
      Returns:
      a different list instance with the element added
    • add

      ImmutableList<E> add(int index, E element)
      Returns a copy of this list that contains all elements of this list and the specified element appended to the end of the list.
      Parameters:
      index - the insertion index
      element - an element
      Returns:
      a different list instance with the element added
    • addAll

      ImmutableList<E> addAll(Iterable<? extends E> c)
      Returns a copy of this list that contains all elements of this list and all elements of the specified collection appended.
      Specified by:
      addAll in interface ImmutableCollection<E>
      Specified by:
      addAll in interface ImmutableSequencedCollection<E>
      Parameters:
      c - a collection to be added to this list
      Returns:
      a different list instance with the elements added
    • addAll

      ImmutableList<E> addAll(int index, Iterable<? extends E> c)
      Returns a copy of this list that contains all elements of this list and all elements of the specified collection appended.
      Parameters:
      index - the insertion index
      c - a collection to be added to this list
      Returns:
      a different list instance with the elements added
    • remove

      ImmutableList<E> remove(E element)
      Returns a copy of this list that contains all elements of this list except the specified element.
      Specified by:
      remove in interface ImmutableCollection<E>
      Specified by:
      remove in interface ImmutableSequencedCollection<E>
      Parameters:
      element - an element
      Returns:
      this list instance if it already does not contain the element, or a different list instance with the element removed
    • removeAt

      ImmutableList<E> removeAt(int index)
      Returns a copy of this list that contains all elements of this list except the element at the specified index
      Parameters:
      index - an index
      Returns:
      a different list instance with the element removed
    • removeRange

      ImmutableList<E> removeRange(int fromIndex, int toIndex)
      Returns a copy of this list that contains all elements of this list except the elements in the specified range.
      Parameters:
      fromIndex - from index (inclusive) of the sub-list
      toIndex - to index (exclusive) of the sub-list
      Returns:
      a different list instance with the element removed
    • removeAll

      ImmutableList<E> removeAll(Iterable<?> c)
      Returns a copy of this list that contains all elements of this list except the elements of the specified collection.
      Specified by:
      removeAll in interface ImmutableCollection<E>
      Specified by:
      removeAll in interface ImmutableSequencedCollection<E>
      Parameters:
      c - a collection with elements to be removed from this set
      Returns:
      this list instance if it already does not contain the elements, or a different list instance with the elements removed
    • retainAll

      ImmutableList<E> retainAll(Iterable<?> c)
      Returns a copy of this list that contains only elements that are in this list and in the specified collection.
      Specified by:
      retainAll in interface ImmutableCollection<E>
      Specified by:
      retainAll in interface ImmutableSequencedCollection<E>
      Parameters:
      c - a collection with elements to be retained in this set
      Returns:
      this list instance if it has not changed, or a different list instance with elements removed
    • reverse

      ImmutableList<E> reverse()
      Returns a reversed copy of this list.

      This operation may be implemented in O(N).

      Use ReadOnlySequencedCollection.readOnlyReversed() if you only need to iterate in the reversed sequence over this list.

      Returns:
      a reversed copy of this list.
    • set

      ImmutableList<E> set(int index, E element)
      Returns a copy of this list that contains all elements of this list and the specified element replaced.
      Parameters:
      element - an element
      Returns:
      this list instance if it has not changed, or a different list instance with the element changed
    • readOnlySubList

      ImmutableList<E> readOnlySubList(int fromIndex, int toIndex)
      Returns a copy of this list that contains only the elements in the given index range.
      Specified by:
      readOnlySubList in interface ReadOnlyList<E>
      Parameters:
      fromIndex - from index (inclusive) of the sub-list
      toIndex - to index (exclusive) of the sub-list
      Returns:
      this list instance if it has not changed, or a different list instance with the element changed
    • toMutable

      List<E> toMutable()
      Returns a mutable copy of this list.
      Specified by:
      toMutable in interface ImmutableCollection<E>
      Returns:
      a mutable copy.