V
- the type of the value objects@ParametersAreNonnullByDefault public interface ValueStack<V> extends Iterable<V>
A stack state can be saved and restored using takeSnapshot()
and
restoreSnapshot(Object)
.
Stacks do not accept null values; if a null value is inserted, a NullPointerException
will be thrown.
Any attempt to pop/swap values on a stack with not enough elements will
throw an IllegalStateException
.
You probably want to extend ValueStackBase
instead of directly
implementing this interface.
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears all values.
|
void |
dup()
Duplicates the top value.
|
boolean |
isEmpty()
Determines whether the stack is empty.
|
V |
peek()
Returns the value at the top of the stack without removing it.
|
V |
peek(int down)
Returns the value the given number of elements below the top of the stack
without removing it.
|
<T extends V> |
peekAs(Class<T> type)
Casts and returns the value at the top of the stack without removing it
|
<T extends V> |
peekAs(Class<T> type,
int down)
Casts and returns the value at a given index in the stack without
removing it
|
void |
poke(int down,
V value)
Replaces the element the given number of elements below the current top
of the stack.
|
void |
poke(V value)
Replaces the current top value with the given value.
|
V |
pop()
Removes the value at the top of the stack and returns it.
|
V |
pop(int down)
Removes the value the given number of elements below the top of the stack.
|
<T extends V> |
popAs(Class<T> type)
Removes and casts the value at the top of the stack, and returns it
|
<T extends V> |
popAs(Class<T> type,
int down)
Removes and casts the value at a given index in the stack, and returns it
|
void |
push(int down,
V value)
Inserts the given value a given number of elements below the current top
of the stack.
|
void |
push(V value)
Pushes the given value onto the stack.
|
void |
restoreSnapshot(Object snapshot)
Restores the stack state as previously returned by
takeSnapshot() . |
int |
size()
Returns the number of elements currently on the stack.
|
void |
swap()
Swaps the top two stack values.
|
void |
swap(int n)
Reverses the order of the top n stack values
|
Object |
takeSnapshot()
Returns an object representing the current state of the stack.
|
boolean isEmpty()
int size()
void clear()
@Nonnull Object takeSnapshot()
void restoreSnapshot(Object snapshot)
takeSnapshot()
.snapshot
- a snapshot object previously returned by takeSnapshot()
void push(V value)
value
- the valuevoid push(int down, V value)
down
- the number of elements to skip before inserting the value (0
being equivalent to push(value))value
- the value@Nonnull V pop()
@Nonnull V pop(int down)
down
- the number of elements to skip before removing the value (0
being equivalent to pop())@Nonnull <T extends V> T popAs(Class<T> type)
T
- type parametertype
- the type to cast to@Nonnull <T extends V> T popAs(Class<T> type, int down)
T
- type parametertype
- the type to cast todown
- the index@Nonnull V peek()
@Nonnull V peek(int down)
down
- the number of elements to skip (0 being equivalent to peek())@Nonnull <T extends V> T peekAs(Class<T> type)
T
- type parametertype
- the type to cast to@Nonnull <T extends V> T peekAs(Class<T> type, int down)
T
- type parametertype
- the type to cast todown
- the index in the stackvoid poke(@Nonnull V value)
value
- the valuevoid poke(int down, V value)
down
- the number of elements to skip before replacing the value (0
being equivalent to poke(value))value
- the value to replace withvoid dup()
void swap(int n)
n
- the number of elements to reversevoid swap()