org.apache.pivot.collections.concurrent
Class SynchronizedStack<T>

java.lang.Object
  extended by org.apache.pivot.collections.concurrent.SynchronizedStack<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>, Stack<T>

public class SynchronizedStack<T>
extends Object
implements Stack<T>

Synchronized implementation of the Stack interface.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Stack
Stack.StackListenerList<T>
 
Constructor Summary
SynchronizedStack(Stack<T> stack)
           
 
Method Summary
 void clear()
          Removes all elements from the collection.
 Comparator<T> getComparator()
          Returns the collection's sort order.
 int getDepth()
          Returns the stack depth.
 ListenerList<StackListener<T>> getStackListeners()
          Returns the stack listener list.
 boolean isEmpty()
          Tests the emptiness of the stack.
 Iterator<T> iterator()
          NOTE Callers must manually synchronize on the SynchronizedStack instance to ensure thread safety during iteration.
 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.
 void setComparator(Comparator<T> comparator)
          Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynchronizedStack

public SynchronizedStack(Stack<T> stack)
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>

clear

public void clear()
Description copied from interface: Collection
Removes all elements from the collection.

Specified by:
clear in interface Collection<T>

isEmpty

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

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

getDepth

public int getDepth()
Description copied from interface: Stack
Returns the stack depth.

Specified by:
getDepth in interface Stack<T>

getComparator

public Comparator<T> getComparator()
Description copied from interface: Collection
Returns the collection's sort order.

Specified by:
getComparator in interface Collection<T>
Returns:
The comparator used to order elements in the collection, or null if the sort order is undefined.
See Also:
Collection.setComparator(Comparator)

setComparator

public void setComparator(Comparator<T> comparator)
Description copied from interface: Collection
Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.

Calling this method more than once with the same comparator will re-sort the collection.

Specified by:
setComparator in interface Collection<T>
Parameters:
comparator - The comparator used to order elements in the collection, or null if the collection is unsorted.

iterator

public Iterator<T> iterator()
NOTE Callers must manually synchronize on the SynchronizedStack instance to ensure thread safety during iteration.

Specified by:
iterator in interface Iterable<T>

getStackListeners

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

Specified by:
getStackListeners in interface Stack<T>