Class Stack<E>
- java.lang.Object
-
- org.apache.tapestry5.commons.util.Stack<E>
-
- Type Parameters:
E
- the type of elements stored in the map
public class Stack<E> extends Object
A simple, streamlined implementation ofStack
. The implementation is not threadsafe.- See Also:
CollectionFactory.newStack()
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the stack, the same as popping off all elements.int
getDepth()
Returns the number of items currently in the stack.Object[]
getSnapshot()
Returns a snapshot of the current state of the stack as an array of objects.boolean
isEmpty()
Returns true if the stack is empty.E
peek()
Returns the top element of the stack without affecting the stack.E
pop()
Pops the top element off the stack and returns it.void
push(E item)
Pushes a new item onto the stack.String
toString()
Describes the stack, listing the element in order of depth (top element first).
-
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Returns true if the stack is empty.
-
getDepth
public int getDepth()
Returns the number of items currently in the stack.
-
clear
public void clear()
Clears the stack, the same as popping off all elements.
-
pop
public E pop()
Pops the top element off the stack and returns it.- Returns:
- the top element of the stack
- Throws:
IllegalStateException
- if the stack is empty
-
peek
public E peek()
Returns the top element of the stack without affecting the stack.- Returns:
- top element on the stack
- Throws:
IllegalStateException
- if the stack is empty
-
toString
public String toString()
Describes the stack, listing the element in order of depth (top element first).
-
getSnapshot
public Object[] getSnapshot()
Returns a snapshot of the current state of the stack as an array of objects. The first object is the deepest in the stack, the last object is the most shallowest (most recently pushed onto the stack). The returned array may be manipulated (it is a copy).- Returns:
- the stack as an object array
-
-