pivot.collections
Interface Stack<T>

All Superinterfaces:
Collection<T>, Iterable<T>, List<T>, Sequence<T>
All Known Implementing Classes:
ArrayStack, LinkedStack, SynchronizedStack

public interface Stack<T>
extends List<T>

Interface representing a last-in, first-out (LIFO) stack when unsorted, and a priority stack when sorted.

Author:
gbrown

Nested Class Summary
 
Nested classes/interfaces inherited from interface pivot.collections.List
List.ListListenerList<T>
 
Nested classes/interfaces inherited from interface pivot.collections.Sequence
Sequence.Search, Sequence.Sort, Sequence.Tree
 
Method Summary
 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 interface pivot.collections.List
add, clear, getLength, getListListeners, insert, remove, setComparator, update
 
Methods inherited from interface pivot.collections.Sequence
get, indexOf, remove
 
Methods inherited from interface pivot.collections.Collection
getComparator
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

push

void push(T item)
"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.

Parameters:
item - The item to push onto the stack.

pop

T pop()
Removes the top item from the stack and returns it.

Throws:
IllegalStateException - If the stack contains no items.

peek

T peek()
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.


poke

T poke(T item)
Replaces the item on top of the stack.

Throws:
IllegalStateException - If the stack contains no items.