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 ofPersistentList
. Null values are not supported (similarly toImmutableList
).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()
andListIterator.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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> Collector<T,?,PersistentLinkedList<T>>
collector()
Deprecated.renamed totoPersistentLinkedList()
to conform with Guava's namingstatic <T> PersistentLinkedList<T>
copyOf(List<T> values)
Returns A new list with the values from the Iterable.static <T> PersistentLinkedList<T>
copyOf(T... values)
Returns a list containing the specified values.PersistentLinkedList<T>
empty()
Replacement for {PersistentList.clear()
that returns an empty instance.T
head()
Returns the value at the start of the list.boolean
isEmpty()
Iterator<T>
iterator()
ListIterator<T>
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.void
replaceAll(UnaryOperator<T> pOperator)
Deprecated.PersistentLinkedList<T>
reversed()
Returns a new list with the elements in the reverse order.int
size()
Returns the number of elements in the list.void
sort(Comparator<? super T> pC)
Deprecated.PersistentLinkedList<T>
tail()
Returns the remainder of the list without the first element.static <T> Collector<T,?,PersistentLinkedList<T>>
toPersistentLinkedList()
Return aCollector
that creates PersistentLinkedLists and can be used inStream.collect(Collector)
.PersistentLinkedList<T>
with(T value)
Returns a new list with value as the head and the old list as the tail.PersistentLinkedList<T>
withAll(List<T> values)
Returns a new list with values as the head and the old list as the tail.PersistentLinkedList<T>
without(@Nullable T value)
Returns a new list omitting the specified value.-
Methods inherited from class java.util.AbstractList
add, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
contains, containsAll, equals, get, hashCode, indexOf, lastIndexOf, listIterator, spliterator, subList, toArray, toArray
-
-
-
-
Method Detail
-
of
public static <T> PersistentLinkedList<T> of()
Returns the empty list.- Returns:
- The empty list
-
of
public static <T> PersistentLinkedList<T> of(T value)
Returns a list containing the specified value.- Returns:
- A list containing the specified value
-
of
public static <T> PersistentLinkedList<T> of(T v1, T v2)
Returns a list containing the specified values.- Returns:
- A list containing the specified values
-
of
public static <T> PersistentLinkedList<T> of(T v1, T v2, T v3)
Returns a list containing the specified values.- Returns:
- A list containing the specified values
-
of
public static <T> PersistentLinkedList<T> of(T v1, T... values)
Returns a list containing the specified values.- Returns:
- A list containing the specified values
-
copyOf
public static <T> PersistentLinkedList<T> copyOf(T... values)
Returns a list containing the specified values.- Returns:
- A list containing the specified values
-
copyOf
public static <T> PersistentLinkedList<T> copyOf(List<T> values)
Returns A new list with the values from the Iterable.- Returns:
- A new list with the values from the Iterable
-
head
public T head()
Returns the value at the start of the list.- Returns:
- The value at the start of the list
-
tail
public PersistentLinkedList<T> tail()
Returns the remainder of the list without the first element.- Returns:
- The remainder of the list without the first element
-
with
public PersistentLinkedList<T> with(T value)
Returns a new list with value as the head and the old list as the tail.- Specified by:
with
in interfacePersistentList<T>
- Returns:
- A new list with value as the head and the old list as the tail
-
withAll
public PersistentLinkedList<T> withAll(List<T> values)
Returns a new list with values as the head and the old list as the tail.- Specified by:
withAll
in interfacePersistentList<T>
- Returns:
- A new list with value sas the head and the old list as the tail
-
without
public PersistentLinkedList<T> without(@Nullable T value)
Returns a new list omitting the specified value. Note: O(N)- Specified by:
without
in interfacePersistentList<T>
- Returns:
- A new list omitting the specified value
-
empty
public PersistentLinkedList<T> empty()
Description copied from interface:PersistentList
Replacement for {PersistentList.clear()
that returns an empty instance.- Specified by:
empty
in interfacePersistentList<T>
-
size
public int size()
Returns the number of elements in the list. Note: O(N)- Specified by:
size
in interfaceCollection<T>
- Specified by:
size
in interfaceList<T>
- Specified by:
size
in classAbstractCollection<T>
- Returns:
- The number of elements in the list
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<T>
- Specified by:
isEmpty
in interfaceList<T>
- Overrides:
isEmpty
in classAbstractCollection<T>
-
reversed
public PersistentLinkedList<T> reversed()
Returns a new list with the elements in the reverse order. This operation runs in O(n).- Specified by:
reversed
in interfacePersistentList<T>
- Returns:
- A new list with the elements in the reverse order
-
listIterator
public ListIterator<T> listIterator(int index)
- Specified by:
listIterator
in interfaceList<T>
- Specified by:
listIterator
in classAbstractSequentialList<T>
-
toPersistentLinkedList
public static <T> Collector<T,?,PersistentLinkedList<T>> toPersistentLinkedList()
Return aCollector
that 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,?,PersistentLinkedList<T>> collector()
Deprecated.renamed totoPersistentLinkedList()
to conform with Guava's namingReturn aCollector
that creates PersistentLinkedLists and can be used inStream.collect(Collector)
. The returned collector does not support parallel streams.
-
replaceAll
@Deprecated public void replaceAll(UnaryOperator<T> pOperator)
Deprecated.- Specified by:
replaceAll
in interfaceList<T>
- Specified by:
replaceAll
in interfacePersistentList<T>
-
sort
@Deprecated public void sort(Comparator<? super T> pC)
Deprecated.
-
-