Class FastStack

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public final class FastStack
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable
    A very simple unsynchronized stack. This one is faster than the java.util-Version.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Object[] contents  
      private int initialSize  
      private int size  
    • Constructor Summary

      Constructors 
      Constructor Description
      FastStack()
      Creates a new empty stack.
      FastStack​(int size)
      Creates a new empty stack with the specified initial storage size.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the stack.
      java.lang.Object clone()
      Returns a clone of the stack.
      java.lang.Object get​(int index)
      Returns the item at the specified slot in the stack.
      boolean isEmpty()
      Returns true if the stack is empty, and false otherwise.
      java.lang.Object peek()
      Returns the object at the top of the stack without removing it.
      java.lang.Object pop()
      Removes and returns the object from the top of the stack.
      void push​(java.lang.Object o)
      Pushes an object onto the stack.
      int size()
      Returns the number of elements in the stack.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • contents

        private java.lang.Object[] contents
      • size

        private int size
      • initialSize

        private int initialSize
    • Constructor Detail

      • FastStack

        public FastStack()
        Creates a new empty stack.
      • FastStack

        public FastStack​(int size)
        Creates a new empty stack with the specified initial storage size.
        Parameters:
        size - the initial storage elements.
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Returns true if the stack is empty, and false otherwise.
        Returns:
        A boolean.
      • size

        public int size()
        Returns the number of elements in the stack.
        Returns:
        The element count.
      • push

        public void push​(java.lang.Object o)
        Pushes an object onto the stack.
        Parameters:
        o - the object.
      • peek

        public java.lang.Object peek()
        Returns the object at the top of the stack without removing it.
        Returns:
        The object at the top of the stack.
      • pop

        public java.lang.Object pop()
        Removes and returns the object from the top of the stack.
        Returns:
        The object.
      • clone

        public java.lang.Object clone()
        Returns a clone of the stack.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A clone.
      • clear

        public void clear()
        Clears the stack.
      • get

        public java.lang.Object get​(int index)
        Returns the item at the specified slot in the stack.
        Parameters:
        index - the index.
        Returns:
        The item.