Package org.simpleframework.xml.stream
Class Stack<T>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<T>
-
- org.simpleframework.xml.stream.Stack<T>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.List<T>
,java.util.RandomAccess
- Direct Known Subclasses:
InputStack
,NodeStack
class Stack<T> extends java.util.ArrayList<T>
TheStack
object is used to provide a lightweight stack implementation. To ensure top performance this stack is not synchronized and keeps track of elements using an array list. A null from either apop
ortop
means that the stack is empty. This allows the stack to be peeked at even if it has not been populated with anything yet.
-
-
Constructor Summary
Constructors Constructor Description Stack(int size)
Constructor for theStack
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
bottom()
This is used to acquire the node from the bottom of the stack.T
pop()
This is used to remove the element from the top of this stack.T
push(T value)
This method is used to add an element to the top of the stack.T
top()
This is used to peek at the element from the top of this stack.-
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
-
-
-
Constructor Detail
-
Stack
public Stack(int size)
Constructor for theStack
object. This is used to create a stack that can be used to keep track of values in a first in last out manner. Typically this is used to determine if an XML element is in or out of context.- Parameters:
size
- this is the initial size of the stack to use
-
-
Method Detail
-
pop
public T pop()
This is used to remove the element from the top of this stack. If the stack is empty then this will return null, as such it is not advisable to push null elements on the stack.- Returns:
- this returns the node element the top of the stack
-
top
public T top()
This is used to peek at the element from the top of this stack. If the stack is empty then this will return null, as such it is not advisable to push null elements on the stack.- Returns:
- this returns the node element the top of the stack
-
bottom
public T bottom()
This is used to acquire the node from the bottom of the stack. If the stack is empty then this will return null, as such it is not advisable to push null elements on the stack.- Returns:
- this returns the element from the bottom of the stack
-
push
public T push(T value)
This method is used to add an element to the top of the stack. Although it is possible to add a null element to the stack it is not advisable, as null is returned when the stack is empty.- Parameters:
value
- this is the element to add to the stack- Returns:
- this returns the actual node that has just been added
-
-