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 E
private final ConsPStack
<E> private static final long
private final int
Fields 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) int
size()
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, sort
Methods inherited from class java.util.AbstractSequentialList
get, iterator
Methods inherited from class java.util.AbstractList
equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, 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
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:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
- Specified by:
listIterator
in classAbstractSequentialList<E>
-
subList
-
plus
Description copied from interface:PStack
Returns a stack consisting of the elements of this with e prepended. -
plusAll
Description copied from interface:PStack
Returns a stack consisting of the elements of this with list prepended in reverse. -
plus
-
plusAll
-
minus
Description copied from interface:PSequence
Returns a sequence consisting of the elements of this without the first occurrence of e. -
minus
-
minusAll
-
with
-
subList
-