java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.AbstractSequentialList<E>
org.pcollections.AbstractUnmodifiableSequentialList<E>
org.pcollections.ConsPStack<E>
- Type Parameters:
E-
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,List<E>,PCollection<E>,PSequence<E>,PStack<E>
public final class ConsPStack<E>
extends AbstractUnmodifiableSequentialList<E>
implements PStack<E>, Serializable
A simple persistent stack.
This implementation is thread-safe (assuming Java's AbstractSequentialList is thread-safe), although its iterators may not be.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ConsPStack<Object> private final Eprivate final ConsPStack<E> private static final longprivate final intFields inherited from class java.util.AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> ConsPStack<E> empty()static <E> ConsPStack<E> from(Collection<? extends E> list) private static <E> ConsPStack<E> listIterator(int index) minus(int i) Returns a sequence consisting of the elements of this without the first occurrence of e.minusAll(Collection<?> list) Returns a stack consisting of the elements of this with e prepended.plusAll(int i, Collection<? extends E> list) plusAll(Collection<? extends E> list) Returns a stack consisting of the elements of this with list prepended in reverse.static <E> ConsPStack<E> singleton(E e) intsize()subList(int start) subList(int start, int end) Methods inherited from class org.pcollections.AbstractUnmodifiableSequentialList
add, add, addAll, addAll, clear, remove, remove, removeAll, removeIf, replaceAll, retainAll, set, sortMethods inherited from class java.util.AbstractSequentialList
get, iteratorMethods inherited from class java.util.AbstractList
equals, hashCode, indexOf, lastIndexOf, listIterator, removeRangeMethods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, 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
add, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
EMPTY
-
first
-
rest
-
size
private final int size
-
-
Constructor Details
-
ConsPStack
private ConsPStack() -
ConsPStack
-
-
Method Details
-
empty
- Type Parameters:
E-- Returns:
- an empty stack
-
singleton
- Type Parameters:
E-- Parameters:
e-- Returns:
- empty().plus(e)
-
from
- Type Parameters:
E-- Parameters:
list-- Returns:
- a stack consisting of the elements of list in the order of list.iterator()
-
from
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>- Specified by:
listIteratorin classAbstractSequentialList<E>
-
subList
-
plus
Description copied from interface:PStackReturns a stack consisting of the elements of this with e prepended. -
plusAll
Description copied from interface:PStackReturns a stack consisting of the elements of this with list prepended in reverse. -
plus
-
plusAll
-
minus
Description copied from interface:PSequenceReturns a sequence consisting of the elements of this without the first occurrence of e. -
minus
-
minusAll
-
with
-
subList
-