- 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:
java.io.Serializable
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.List<E>
,PCollection<E>
,PSequence<E>
,PStack<E>
public final class ConsPStack<E> extends AbstractUnmodifiableSequentialList<E> implements PStack<E>, java.io.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static ConsPStack<java.lang.Object>
EMPTY
private E
first
private ConsPStack<E>
rest
private static long
serialVersionUID
private int
size
-
Constructor Summary
Constructors Modifier Constructor Description private
ConsPStack()
private
ConsPStack(E first, ConsPStack<E> rest)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <E> ConsPStack<E>
empty()
static <E> ConsPStack<E>
from(java.util.Collection<? extends E> list)
private static <E> ConsPStack<E>
from(java.util.Iterator<? extends E> i)
java.util.ListIterator<E>
listIterator(int index)
ConsPStack<E>
minus(int i)
ConsPStack<E>
minus(java.lang.Object e)
Returns a sequence consisting of the elements of this without the first occurrence of e.ConsPStack<E>
minusAll(java.util.Collection<?> list)
ConsPStack<E>
plus(int i, E e)
ConsPStack<E>
plus(E e)
Returns a stack consisting of the elements of this with e prepended.ConsPStack<E>
plusAll(int i, java.util.Collection<? extends E> list)
ConsPStack<E>
plusAll(java.util.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()
ConsPStack<E>
subList(int start)
ConsPStack<E>
subList(int start, int end)
ConsPStack<E>
with(int i, E e)
-
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.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.List
add, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
EMPTY
private static final ConsPStack<java.lang.Object> EMPTY
-
first
private final E first
-
rest
private final ConsPStack<E> rest
-
size
private final int size
-
-
Constructor Detail
-
ConsPStack
private ConsPStack()
-
ConsPStack
private ConsPStack(E first, ConsPStack<E> rest)
-
-
Method Detail
-
empty
public static <E> ConsPStack<E> empty()
- Type Parameters:
E
-- Returns:
- an empty stack
-
singleton
public static <E> ConsPStack<E> singleton(E e)
- Type Parameters:
E
-- Parameters:
e
-- Returns:
- empty().plus(e)
-
from
public static <E> ConsPStack<E> from(java.util.Collection<? extends E> list)
- Type Parameters:
E
-- Parameters:
list
-- Returns:
- a stack consisting of the elements of list in the order of list.iterator()
-
from
private static <E> ConsPStack<E> from(java.util.Iterator<? extends E> i)
-
size
public int size()
-
listIterator
public java.util.ListIterator<E> listIterator(int index)
-
subList
public ConsPStack<E> subList(int start, int end)
-
plus
public ConsPStack<E> plus(E e)
Description copied from interface:PStack
Returns a stack consisting of the elements of this with e prepended.
-
plusAll
public ConsPStack<E> plusAll(java.util.Collection<? extends E> list)
Description copied from interface:PStack
Returns a stack consisting of the elements of this with list prepended in reverse.
-
plus
public ConsPStack<E> plus(int i, E e)
-
plusAll
public ConsPStack<E> plusAll(int i, java.util.Collection<? extends E> list)
-
minus
public ConsPStack<E> minus(java.lang.Object e)
Description copied from interface:PSequence
Returns a sequence consisting of the elements of this without the first occurrence of e.
-
minus
public ConsPStack<E> minus(int i)
-
minusAll
public ConsPStack<E> minusAll(java.util.Collection<?> list)
-
with
public ConsPStack<E> with(int i, E e)
-
subList
public ConsPStack<E> subList(int start)
-
-