public class ImmutableStack<T> extends Object implements Iterable<T>
push(Object) and pop() operations create new
stacks.| Modifier | Constructor and Description |
|---|---|
protected |
ImmutableStack(T[] entries) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(T entry) |
static <T> ImmutableStack<T> |
emptyStack() |
boolean |
equals(Object o) |
T |
get(int i) |
static int |
getMaxSize() |
int |
hashCode() |
boolean |
isEmpty() |
Iterator<T> |
iterator() |
protected T[] |
makeInternalArray(int size) |
protected ImmutableStack<T> |
makeStack(T[] tmpEntries) |
T |
peek() |
ImmutableStack<T> |
pop() |
ImmutableStack<T> |
popAll(ImmutableStack<T> other) |
ImmutableStack<T> |
push(T entry) |
ImmutableStack<T> |
pushAll(ImmutableStack<T> other) |
ImmutableStack<T> |
replaceTop(T t)
return a new stack with the top replaced with t
|
ImmutableStack<T> |
reverse() |
int |
size() |
boolean |
topMatches(ImmutableStack<T> other) |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorprotected ImmutableStack(T[] entries)
public static int getMaxSize()
public static final <T> ImmutableStack<T> emptyStack()
public ImmutableStack<T> push(T entry)
protected T[] makeInternalArray(int size)
protected ImmutableStack<T> makeStack(T[] tmpEntries)
public T peek()
EmptyStackException - if stack is emptypublic ImmutableStack<T> pop()
EmptyStackException - if stack is emptypublic boolean isEmpty()
public int size()
public T get(int i)
public boolean contains(T entry)
public boolean topMatches(ImmutableStack<T> other) throws IllegalArgumentException
true iff other.size() = k, k <= this.size(), and the top k
elements of this equal otherIllegalArgumentException - if other == nullpublic ImmutableStack<T> reverse()
public ImmutableStack<T> popAll(ImmutableStack<T> other)
public ImmutableStack<T> pushAll(ImmutableStack<T> other)
public ImmutableStack<T> replaceTop(T t)