org.apache.pivot.collections
Interface Stack<T>

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

public interface Stack<T>
extends Collection<T>

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


Nested Class Summary
static class Stack.StackListenerList<T>
          Stack listener list.
 
Method Summary
 int getDepth()
          Returns the stack depth.
 ListenerList<StackListener<T>> getStackListeners()
          Returns the stack listener list.
 boolean isEmpty()
          Tests the emptiness of the stack.
 T peek()
          Returns the item on top of the stack without removing it from 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 org.apache.pivot.collections.Collection
clear, getComparator, setComparator
 
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.


isEmpty

boolean isEmpty()
Tests the emptiness of the stack.

Specified by:
isEmpty in interface Collection<T>
Returns:
true if the stack contains no items; false, otherwise.

getDepth

int getDepth()
Returns the stack depth.


getStackListeners

ListenerList<StackListener<T>> getStackListeners()
Returns the stack listener list.