- 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>
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.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacePersistentList.Builder<E extends @Nullable Object>A generic builder of the persistent list.Nested classes/interfaces inherited from interface ImmutableList
ImmutableList.SubList<E> -
Method Summary
Modifier and TypeMethodDescriptionReturns a new persistent list with the specifiedelementinserted at the specifiedindex.Returns a new persistent list with the specifiedelementappended.addAll(int index, Collection<? extends E> elements) Returns the result of inserting the specifiedccollection at the specifiedindex.default PersistentList<E> Returns the result of appending all elements of the specifiedelementsarray to this list.default PersistentList<E> Returns the result of appending all elements of the specifiedelementscollection to this list.addAll(Collection<? extends E> elements) Returns the result of appending all elements of the specifiedelementscollection to this list.default PersistentList<E> Returns the result of appending all elements of the specifiedelementssequence to this list.builder()Returns a new builder with the same contents as this collection.clear()Returns an empty persistent list.static PersistentList<Character> from(CharSequence chars) Returns a persistent list containing all characters.static <T extends @Nullable Object>
PersistentList<T> Returns a persistent list containing all elements of the specified collection.static <T extends @Nullable Object>
PersistentList<T> Returns a persistent list containing all elements of the specified sequence.static <T extends @Nullable Object>
PersistentList<T> from(T[] array) Returns a persistent list containing all elements of the specified array.default PersistentList<E> static <E extends @Nullable Object>
PersistentList<E> of()Returns an empty persistent list.static <E extends @Nullable Object>
PersistentList<E> of(E... elements) Returns a new persistent list of the specified elements.Returns the result of removing the first appearance of the specifiedelementfrom this list.default PersistentList<E> Returns the result of removing all elements in this list that are also contained in the specifiedelementsarray.default PersistentList<E> Returns the result of removing all elements in this list that are also contained in the specifiedelementscollection.removeAll(Collection<? extends E> elements) Returns the result of removing all elements in this list that are also contained in the specifiedelementscollection.Returns the result of removing all elements in this list that match the specifiedpredicate.default PersistentList<E> Returns the result of removing all elements in this list that are also contained in the specifiedelementssequence.removeAt(int index) Returns a new persistent list with the element at the specifiedindexremoved.retainAll(Collection<? extends E> elements) Returns all elements in this list that are also contained in the specifiedelementscollection.Returns a new persistent list with the element at the specifiedindexreplaced with the specifiedelement.Methods inherited from interface ImmutableCollection
contains, containsAll, isEmpty, iterator, parallelStream, size, streamMethods inherited from interface ImmutableList
get, indexOf, lastIndexOf, listIterator, listIterator, subListMethods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface PersistentCollection
intersect
-
Method Details
-
of
Returns an empty persistent list. -
of
Returns a new persistent list of the specified elements. -
from
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
buildon it and returns the result. -
from
Returns a persistent list containing all elements of the specified array. -
from
Returns a persistent list containing all elements of the specified sequence. -
from
Returns a persistent list containing all characters. -
add
Returns a new persistent list with the specifiedelementappended.- Specified by:
addin interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent collection with the specified
elementadded; or this instance if this collection does not support duplicates and it already contains the element.
-
addAll
Returns the result of appending all elements of the specified
elementscollection to this list.The elements are appended in the order they appear in the specified collection.
- Specified by:
addAllin interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent list with elements of the specified
elementscollection appended; or this instance if the specified collection is empty.
-
remove
Returns the result of removing the first appearance of the specifiedelementfrom this list.- Specified by:
removein interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent list with the first appearance of the specified
elementremoved; or this instance if there is no such element in this list.
-
removeAll
Returns the result of removing all elements in this list that are also contained in the specifiedelementscollection.- Specified by:
removeAllin interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent list with elements in this list that are also
contained in the specified
elementscollection removed; or this instance if no modifications were made in the result of this operation.
-
removeAll
Returns the result of removing all elements in this list that match the specifiedpredicate.- Specified by:
removeAllin interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent list with elements matching the specified
predicateremoved; or this instance if no elements match the predicate.
-
retainAll
Returns all elements in this list that are also contained in the specifiedelementscollection.- Specified by:
retainAllin interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent list with elements in this list that are also
contained in the specified
elementscollection; 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:
clearin interfacePersistentCollection<E extends @Nullable Object>
-
addAll
Returns the result of inserting the specifiedccollection at the specifiedindex.- Returns:
- a new persistent list with the specified
ccollection inserted at the specifiedindex; or this instance if the specified collection is empty. - Throws:
IndexOutOfBoundsException- ifindexis out of bounds of this list.
-
set
Returns a new persistent list with the element at the specifiedindexreplaced with the specifiedelement.- Throws:
IndexOutOfBoundsException- ifindexis out of bounds of this list.
-
add
Returns a new persistent list with the specifiedelementinserted at the specifiedindex.- Throws:
IndexOutOfBoundsException- ifindexis out of bounds of this list.
-
removeAt
Returns a new persistent list with the element at the specifiedindexremoved.- Throws:
IndexOutOfBoundsException- ifindexis out of bounds of this list.
-
builder
PersistentList.Builder<E> builder()Description copied from interface:PersistentCollectionReturns a new builder with the same contents as this collection.
The builder can be used to efficiently perform multiple modification operations.
- Specified by:
builderin interfacePersistentCollection<E extends @Nullable Object>
-
mutate
-
addAll
Returns the result of appending all elements of the specified
elementscollection to this list.The elements are appended in the order they appear in the specified collection.
- Specified by:
addAllin interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent list with elements of the specified
elementscollection appended; or this instance if the specified collection is empty.
-
addAll
Returns the result of appending all elements of the specified
elementsarray to this list.The elements are appended in the order they appear in the specified array.
- Specified by:
addAllin interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent list with elements of the specified
elementsarray appended; or this instance if the specified array is empty.
-
addAll
Returns the result of appending all elements of the specified
elementssequence to this list.The elements are appended in the order they appear in the specified sequence.
- Specified by:
addAllin interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent list with elements of the specified
elementssequence appended; or this instance if the specified sequence is empty.
-
removeAll
Returns the result of removing all elements in this list that are also contained in the specifiedelementscollection.- Specified by:
removeAllin interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent list with elements in this list that are also
contained in the specified
elementscollection removed; or this instance if no modifications were made in the result of this operation.
-
removeAll
Returns the result of removing all elements in this list that are also contained in the specifiedelementsarray.- Specified by:
removeAllin interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent list with elements in this list that are also
contained in the specified
elementsarray removed; or this instance if no modifications were made in the result of this operation.
-
removeAll
Returns the result of removing all elements in this list that are also contained in the specifiedelementssequence.- Specified by:
removeAllin interfacePersistentCollection<E extends @Nullable Object>- Returns:
- a new persistent list with elements in this list that are also
contained in the specified
elementssequence removed; or this instance if no modifications were made in the result of this operation.
-