org.pentaho.reporting.libraries.base.util
Class FastStack

java.lang.Object
  extended by org.pentaho.reporting.libraries.base.util.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, which is based on the synchronized java.util.Vector class.

Author:
Thomas Morgner
See Also:
Serialized Form

Constructor Summary
FastStack()
          Creates a new stack with an initial size and growth of 10 items.
FastStack(int size)
          Creates a new stack with an initial size and growth as specified.
 
Method Summary
 void clear()
          Removes all contents from the stack.
 java.lang.Object clone()
          Creates a shallow copy of the stack.
 java.lang.Object get(int index)
          Returns the element from the stack at the given index-position.
 boolean isEmpty()
          Checks whether the stack is empty.
 java.lang.Object peek()
          Loads the top-most element from the stack, without removing it from the stack.
 java.lang.Object pop()
          Loads the top-most element from the stack and removes it from the stack at the same time.
 void push(java.lang.Object o)
          Pushes a new object on 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
 

Constructor Detail

FastStack

public FastStack()
Creates a new stack with an initial size and growth of 10 items.


FastStack

public FastStack(int size)
Creates a new stack with an initial size and growth as specified.

Parameters:
size - the initial size and growth.
Method Detail

isEmpty

public boolean isEmpty()
Checks whether the stack is empty.

Returns:
true, if the stack is empty, false otherwise.

size

public int size()
Returns the number of elements in the stack.

Returns:
the stack size.

push

public void push(java.lang.Object o)
Pushes a new object on the stack. Null-references are allowed.

Parameters:
o - the object, maybe null.

peek

public java.lang.Object peek()
Loads the top-most element from the stack, without removing it from the stack.

Returns:
the top-most object.
Throws:
java.util.EmptyStackException - if the stack is empty.

pop

public java.lang.Object pop()
Loads the top-most element from the stack and removes it from the stack at the same time.

Returns:
the top-most object.
Throws:
java.util.EmptyStackException - if the stack is empty.

clone

public java.lang.Object clone()
Creates a shallow copy of the stack.

Overrides:
clone in class java.lang.Object
Returns:
the cloned stack.

clear

public void clear()
Removes all contents from the stack.


get

public java.lang.Object get(int index)
Returns the element from the stack at the given index-position.

Parameters:
index - the element's index.
Returns:
the object.
Throws:
java.lang.IndexOutOfBoundsException - if the index given is greater than the number of objects in the stack.