org.apache.pivot.collections
Class ArrayStack<T>

java.lang.Object
  extended by org.apache.pivot.collections.ArrayList<T>
      extended by org.apache.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.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Stack
Stack.StackListenerList<T>
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.List
List.ItemIterator<T>, List.ListListenerList<T>
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Sequence
Sequence.Tree
 
Field Summary
 
Fields inherited from class org.apache.pivot.collections.ArrayList
DEFAULT_CAPACITY
 
Constructor Summary
ArrayStack()
           
ArrayStack(Comparator<T> comparator)
           
ArrayStack(int capacity)
           
 
Method Summary
 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 class org.apache.pivot.collections.ArrayList
add, binarySearch, binarySearch, clear, ensureCapacity, equals, get, getCapacity, getComparator, getLength, getListListeners, hashCode, indexOf, insert, iterator, remove, remove, setComparator, sort, sort, sort, toArray, toString, trimToSize, update
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.pivot.collections.Collection
clear, getComparator, setComparator
 
Methods inherited from interface java.lang.Iterable
iterator
 

Constructor Detail

ArrayStack

public ArrayStack()

ArrayStack

public ArrayStack(Comparator<T> comparator)

ArrayStack

public ArrayStack(int capacity)
Method Detail

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>

isEmpty

public boolean isEmpty()
Description copied from interface: Stack
Tests the emptiness of the stack.

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

getStackListeners

public ListenerList<StackListener<T>> getStackListeners()
Description copied from interface: Stack
Returns the stack listener list.

Specified by:
getStackListeners in interface Stack<T>