Package org.sosy_lab.common.collect
Class PersistentLinkedList<T>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.AbstractSequentialList<T>
org.sosy_lab.common.collect.PersistentLinkedList<T>
- All Implemented Interfaces:
Iterable<T>,Collection<T>,List<T>,PersistentList<T>
@Immutable(containerOf="T")
public final class PersistentLinkedList<T>
extends AbstractSequentialList<T>
implements PersistentList<T>
A single-linked-list implementation of
PersistentList. Null values are not supported
(similarly to ImmutableList).
Adding to the front of the list needs only O(1) time and memory.
This implementation supports almost all operations, except for the ListIterator.hasPrevious() and ListIterator.previous() methods of its list iterator.
This means you cannot traverse this list in reverse order.
All instances of this class are fully-thread safe. However, note that each modifying operation allocates a new instance whose reference needs to be published safely in order to be usable by other threads. Two concurrent accesses to a modifying operation on the same instance will create two new maps, each reflecting exactly the operation executed by the current thread, and not reflecting the operation executed by the other thread.
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Collector<T,?, PersistentLinkedList<T>> Deprecated.static <T> PersistentLinkedList<T>Returns A new list with the values from the Iterable.static <T> PersistentLinkedList<T>copyOf(T... values) Returns a list containing the specified values.empty()Replacement for {PersistentList.clear()that returns an empty instance.head()Returns the value at the start of the list for non-empty lists.booleanisEmpty()iterator()listIterator(int index) static <T> PersistentLinkedList<T>of()Returns the empty list.static <T> PersistentLinkedList<T>of(T value) Returns a list containing the specified value.static <T> PersistentLinkedList<T>of(T v1, T v2) Returns a list containing the specified values.static <T> PersistentLinkedList<T>of(T v1, T... values) Returns a list containing the specified values.static <T> PersistentLinkedList<T>of(T v1, T v2, T v3) Returns a list containing the specified values.voidreplaceAll(UnaryOperator<T> pOperator) Deprecated.reversed()Returns a new list with the elements in the reverse order.intsize()Returns the number of elements in the list.voidsort(Comparator<? super T> pC) Deprecated.tail()Returns the remainder of the list without the first element for non-empty lists.static <T> Collector<T,?, PersistentLinkedList<T>> Return aCollectorthat creates PersistentLinkedLists and can be used inStream.collect(Collector).Returns a new list with value as the head and the old list as the tail.Returns a new list with values as the head and the old list as the tail.Returns a new list omitting the specified value.Methods inherited from class java.util.AbstractList
add, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
contains, containsAll, equals, get, hashCode, indexOf, lastIndexOf, listIterator, spliterator, subList, toArray, toArray
-
Method Details
-
of
Returns the empty list.- Returns:
- The empty list
-
of
Returns a list containing the specified value.- Returns:
- A list containing the specified value
-
of
Returns a list containing the specified values.- Returns:
- A list containing the specified values
-
of
Returns a list containing the specified values.- Returns:
- A list containing the specified values
-
of
Returns a list containing the specified values.- Returns:
- A list containing the specified values
-
copyOf
Returns a list containing the specified values.- Returns:
- A list containing the specified values
-
copyOf
Returns A new list with the values from the Iterable.- Returns:
- A new list with the values from the Iterable
-
head
Returns the value at the start of the list for non-empty lists.- Returns:
- The value at the start of the list
- Throws:
NoSuchElementException- if the list is empty.
-
tail
Returns the remainder of the list without the first element for non-empty lists.- Returns:
- The remainder of the list without the first element
- Throws:
IllegalStateException- if the list is empty.
-
with
Returns a new list with value as the head and the old list as the tail.- Specified by:
within interfacePersistentList<T>- Returns:
- A new list with value as the head and the old list as the tail
-
withAll
Returns a new list with values as the head and the old list as the tail.- Specified by:
withAllin interfacePersistentList<T>- Returns:
- A new list with value sas the head and the old list as the tail
-
without
Returns a new list omitting the specified value. Note: O(N)- Specified by:
withoutin interfacePersistentList<T>- Returns:
- A new list omitting the specified value
-
empty
Description copied from interface:PersistentListReplacement for {PersistentList.clear()that returns an empty instance.- Specified by:
emptyin interfacePersistentList<T>
-
size
public int size()Returns the number of elements in the list. Note: O(N)- Specified by:
sizein interfaceCollection<T>- Specified by:
sizein interfaceList<T>- Specified by:
sizein classAbstractCollection<T>- Returns:
- The number of elements in the list
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<T>- Specified by:
isEmptyin interfaceList<T>- Overrides:
isEmptyin classAbstractCollection<T>
-
reversed
Returns a new list with the elements in the reverse order. This operation runs in O(n).- Specified by:
reversedin interfacePersistentList<T>- Returns:
- A new list with the elements in the reverse order
-
iterator
-
listIterator
- Specified by:
listIteratorin interfaceList<T>- Specified by:
listIteratorin classAbstractSequentialList<T>
-
toPersistentLinkedList
Return aCollectorthat creates PersistentLinkedLists and can be used inStream.collect(Collector). The returned collector does not support parallel streams. -
collector
@Deprecated @InlineMe(replacement="PersistentLinkedList.toPersistentLinkedList()", imports="org.sosy_lab.common.collect.PersistentLinkedList") public static <T> Collector<T,?, collector()PersistentLinkedList<T>> Deprecated.renamed totoPersistentLinkedList()to conform with Guava's namingReturn aCollectorthat creates PersistentLinkedLists and can be used inStream.collect(Collector). The returned collector does not support parallel streams. -
replaceAll
Deprecated.- Specified by:
replaceAllin interfaceList<T>- Specified by:
replaceAllin interfacePersistentList<T>
-
sort
Deprecated.
-
toPersistentLinkedList()to conform with Guava's naming