Package org.apache.pivot.collections
Class LinkedStack<T>
- java.lang.Object
-
- org.apache.pivot.collections.LinkedStack<T>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<T>
,Collection<T>
,Stack<T>
public class LinkedStack<T> extends java.lang.Object implements Stack<T>, java.io.Serializable
Implementation of theStack
interface that is backed by a linked list.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LinkedStack()
LinkedStack(int maxDepth)
LinkedStack(int maxDepth, java.util.Comparator<T> comparator)
LinkedStack(java.util.Comparator<T> comparator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all elements from the collection.java.util.Comparator<T>
getComparator()
Returns the collection's sort order.int
getDepth()
int
getMaxDepth()
ListenerList<StackListener<T>>
getStackListeners()
boolean
isEmpty()
Tests the emptiness of the stack.java.util.Iterator<T>
iterator()
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(java.util.Comparator<T> comparator)
Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.void
setMaxDepth(int maxDepth)
Set the maximum depth permitted for this stack, 0 means unlimited.
-
-
-
Method Detail
-
getMaxDepth
public int getMaxDepth()
- Specified by:
getMaxDepth
in interfaceStack<T>
- Returns:
- The maximum depth this stack is permitted to reach, where 0 means unlimited.
-
setMaxDepth
public void setMaxDepth(int maxDepth)
Set the maximum depth permitted for this stack, 0 means unlimited.- Specified by:
setMaxDepth
in interfaceStack<T>
- Parameters:
maxDepth
- The new maximum depth for this stack.
-
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.If there is a maximum stack depth defined and the stack goes past this maximum depth, the deepest item (which could be this new item, depending on the comparator) will be removed.
-
pop
public T pop()
Description copied from interface:Stack
Removes the top item from the stack and returns it.
-
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.
-
clear
public void clear()
Description copied from interface:Collection
Removes all elements from the collection.- Specified by:
clear
in interfaceCollection<T>
-
isEmpty
public boolean isEmpty()
Description copied from interface:Stack
Tests the emptiness of the stack.
-
getDepth
public int getDepth()
-
getComparator
public java.util.Comparator<T> getComparator()
Description copied from interface:Collection
Returns the collection's sort order.- Specified by:
getComparator
in interfaceCollection<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(java.util.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 interfaceCollection<T>
- Parameters:
comparator
- The comparator used to order elements in the collection, or null if the collection is unsorted.
-
iterator
public java.util.Iterator<T> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<T>
-
getStackListeners
public ListenerList<StackListener<T>> getStackListeners()
- Specified by:
getStackListeners
in interfaceStack<T>
- Returns:
- The stack listener list.
-
-