Class Stack<T>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess, SequencedCollection<T>
Direct Known Subclasses:
InputStack, NodeStack

class Stack<T> extends ArrayList<T>
The Stack 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 a pop or top 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 Details

    • Stack

      public Stack(int size)
      Constructor for the Stack 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 Details

    • 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