pivot.collections
Class ArrayStack<T>
java.lang.Object
pivot.collections.ArrayList<T>
pivot.collections.ArrayStack<T>
- All Implemented Interfaces:
- Serializable, Iterable<T>, Collection<T>, List<T>, Sequence<T>, Stack<T>
public class ArrayStack<T>
- extends ArrayList<T>
- implements Stack<T>
Implementation of the Stack
interface that is backed by an
array.
- Author:
- gbrown
- See Also:
- Serialized Form
Method Summary |
int |
getRemainingCapacity()
|
T |
peek()
Returns the item on top of the stack without removing it from the stack. |
T |
poke(T item)
Replaces the item on top of the stack. |
T |
pop()
Removes the top item from the stack and returns it. |
void |
push(T item)
"Pushes" an item onto the stack. |
Methods inherited from class pivot.collections.ArrayList |
add, clear, get, getComparator, getLength, getListListeners, indexOf, insert, iterator, remove, remove, setComparator, toArray, toString, update |
ArrayStack
public ArrayStack()
ArrayStack
public ArrayStack(List<T> items)
push
public void push(T item)
- Description copied from interface:
Stack
- "Pushes" an item onto the stack. If the stack is unsorted, the item is
added at the top of the stack (getLength()). Otherwise, it is
inserted at the appropriate index.
- Specified by:
push
in interface Stack<T>
- Parameters:
item
- The item to push onto the stack.
pop
public T pop()
- Description copied from interface:
Stack
- Removes the top item from the stack and returns it.
- Specified by:
pop
in interface Stack<T>
peek
public T peek()
- Description copied from interface:
Stack
- Returns the item on top of the stack without removing it from the stack.
Returns null if the stack contains no items. Will also return null if the
top item in the stack is null. getLength() can be used to
distinguish between these two cases.
- Specified by:
peek
in interface Stack<T>
poke
public T poke(T item)
- Description copied from interface:
Stack
- Replaces the item on top of the stack.
- Specified by:
poke
in interface Stack<T>
getRemainingCapacity
public int getRemainingCapacity()