Class Stack<E>
java.lang.Object
org.apache.tapestry5.commons.util.Stack<E>
- Type Parameters:
E
- the type of elements stored in the map
A simple, streamlined implementation of
Stack
. The implementation is not threadsafe.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the stack, the same as popping off all elements.int
getDepth()
Returns the number of items currently in the stack.Object[]
Returns a snapshot of the current state of the stack as an array of objects.boolean
isEmpty()
Returns true if the stack is empty.peek()
Returns the top element of the stack without affecting the stack.pop()
Pops the top element off the stack and returns it.void
Pushes a new item onto the stack.toString()
Describes the stack, listing the element in order of depth (top element first).
-
Constructor Details
-
Stack
public Stack()Normal constructor supporting an initial size of 20. -
Stack
- Parameters:
initialSize
- the initial size of the internal array (which will be expanded as necessary). For best efficiency, set this to the maximum depth of the stack.
-
-
Method Details
-
isEmpty
Returns true if the stack is empty. -
getDepth
Returns the number of items currently in the stack. -
clear
Clears the stack, the same as popping off all elements. -
push
Pushes a new item onto the stack. -
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
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
Describes the stack, listing the element in order of depth (top element first). -
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
-