Interface PersistentList<E extends @Nullable Object>

Type Parameters:
E - the type of elements contained in the list. The persistent list is covariant on its element type.
All Superinterfaces:
ImmutableCollection<E>, ImmutableList<E>, Iterable<E>, PersistentCollection<E>

public interface PersistentList<E extends @Nullable Object> extends ImmutableList<E>, PersistentCollection<E>

A generic persistent ordered collection of elements that supports adding and removing elements.

Modification operations return new instances of the persistent list with the modification applied.

  • Method Details

    • of

      static <E extends @Nullable Object> PersistentList<E> of()
      Returns an empty persistent list.
    • of

      @SafeVarargs static <E extends @Nullable Object> PersistentList<E> of(E... elements)
      Returns a new persistent list of the specified elements.
    • from

      static <T extends @Nullable Object> PersistentList<T> from(Iterable<T> iterable)

      Returns a persistent list containing all elements of the specified collection.

      If the specified collection is already a persistent list, returns it as is. If the specified collection is a persistent list builder, calls build on it and returns the result.

    • from

      static <T extends @Nullable Object> PersistentList<T> from(T[] array)
      Returns a persistent list containing all elements of the specified array.
    • from

      static <T extends @Nullable Object> PersistentList<T> from(Stream<? extends T> stream)
      Returns a persistent list containing all elements of the specified sequence.
    • from

      static PersistentList<Character> from(CharSequence chars)
      Returns a persistent list containing all characters.
    • add

      PersistentList<E> add(E element)
      Returns a new persistent list with the specified element appended.
      Specified by:
      add in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent collection with the specified element added; or this instance if this collection does not support duplicates and it already contains the element.
    • addAll

      PersistentList<E> addAll(Collection<? extends E> elements)

      Returns the result of appending all elements of the specified elements collection to this list.

      The elements are appended in the order they appear in the specified collection.

      Specified by:
      addAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent list with elements of the specified elements collection appended; or this instance if the specified collection is empty.
    • remove

      PersistentList<E> remove(E element)
      Returns the result of removing the first appearance of the specified element from this list.
      Specified by:
      remove in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent list with the first appearance of the specified element removed; or this instance if there is no such element in this list.
    • removeAll

      PersistentList<E> removeAll(Collection<? extends E> elements)
      Returns the result of removing all elements in this list that are also contained in the specified elements collection.
      Specified by:
      removeAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent list with elements in this list that are also contained in the specified elements collection removed; or this instance if no modifications were made in the result of this operation.
    • removeAll

      PersistentList<E> removeAll(Predicate<? super E> predicate)
      Returns the result of removing all elements in this list that match the specified predicate.
      Specified by:
      removeAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent list with elements matching the specified predicate removed; or this instance if no elements match the predicate.
    • retainAll

      PersistentList<E> retainAll(Collection<? extends E> elements)
      Returns all elements in this list that are also contained in the specified elements collection.
      Specified by:
      retainAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent list with elements in this list that are also contained in the specified elements collection; or this instance if no modifications were made in the result of this operation.
    • clear

      PersistentList<E> clear()
      Returns an empty persistent list.
      Specified by:
      clear in interface PersistentCollection<E extends @Nullable Object>
    • addAll

      PersistentList<E> addAll(int index, Collection<? extends E> elements)
      Returns the result of inserting the specified c collection at the specified index.
      Returns:
      a new persistent list with the specified c collection inserted at the specified index; or this instance if the specified collection is empty.
      Throws:
      IndexOutOfBoundsException - if index is out of bounds of this list.
    • set

      PersistentList<E> set(int index, E element)
      Returns a new persistent list with the element at the specified index replaced with the specified element.
      Throws:
      IndexOutOfBoundsException - if index is out of bounds of this list.
    • add

      PersistentList<E> add(int index, E element)
      Returns a new persistent list with the specified element inserted at the specified index.
      Throws:
      IndexOutOfBoundsException - if index is out of bounds of this list.
    • removeAt

      PersistentList<E> removeAt(int index)
      Returns a new persistent list with the element at the specified index removed.
      Throws:
      IndexOutOfBoundsException - if index is out of bounds of this list.
    • builder

      Description copied from interface: PersistentCollection

      Returns a new builder with the same contents as this collection.

      The builder can be used to efficiently perform multiple modification operations.

      Specified by:
      builder in interface PersistentCollection<E extends @Nullable Object>
    • mutate

      default PersistentList<E> mutate(Consumer<? super List<E>> mutator)
    • addAll

      default PersistentList<E> addAll(Iterable<? extends E> elements)

      Returns the result of appending all elements of the specified elements collection to this list.

      The elements are appended in the order they appear in the specified collection.

      Specified by:
      addAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent list with elements of the specified elements collection appended; or this instance if the specified collection is empty.
    • addAll

      default PersistentList<E> addAll(E[] elements)

      Returns the result of appending all elements of the specified elements array to this list.

      The elements are appended in the order they appear in the specified array.

      Specified by:
      addAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent list with elements of the specified elements array appended; or this instance if the specified array is empty.
    • addAll

      default PersistentList<E> addAll(Stream<? extends E> elements)

      Returns the result of appending all elements of the specified elements sequence to this list.

      The elements are appended in the order they appear in the specified sequence.

      Specified by:
      addAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent list with elements of the specified elements sequence appended; or this instance if the specified sequence is empty.
    • removeAll

      default PersistentList<E> removeAll(Iterable<? extends E> elements)
      Returns the result of removing all elements in this list that are also contained in the specified elements collection.
      Specified by:
      removeAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent list with elements in this list that are also contained in the specified elements collection removed; or this instance if no modifications were made in the result of this operation.
    • removeAll

      default PersistentList<E> removeAll(E[] elements)
      Returns the result of removing all elements in this list that are also contained in the specified elements array.
      Specified by:
      removeAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent list with elements in this list that are also contained in the specified elements array removed; or this instance if no modifications were made in the result of this operation.
    • removeAll

      default PersistentList<E> removeAll(Stream<? extends E> elements)
      Returns the result of removing all elements in this list that are also contained in the specified elements sequence.
      Specified by:
      removeAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent list with elements in this list that are also contained in the specified elements sequence removed; or this instance if no modifications were made in the result of this operation.