org.apache.pivot.collections
Class LinkedStack<T>
java.lang.Object
org.apache.pivot.collections.LinkedList<T>
org.apache.pivot.collections.LinkedStack<T>
- All Implemented Interfaces:
- Serializable, Iterable<T>, Collection<T>, List<T>, Sequence<T>, Stack<T>
public class LinkedStack<T>
- extends LinkedList<T>
- implements Stack<T>
Implementation of the Stack
interface that is backed by a linked
list.
- See Also:
- Serialized Form
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.LinkedList |
add, clear, equals, get, getComparator, getLength, getListListeners, hashCode, indexOf, insert, iterator, remove, remove, setComparator, toString, update |
LinkedStack
public LinkedStack()
LinkedStack
public LinkedStack(Comparator<T> comparator)
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>