org.jawk.util
Class ArrayStackImpl<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<E>
              extended by org.jawk.util.ArrayStackImpl<E>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess, MyStack<E>

public class ArrayStackImpl<E>
extends java.util.ArrayList<E>
implements MyStack<E>

A stack implemented with an ArrayList. Unlike the java.util.Stack which uses a java.util.Vector as a storage mechanism, this implementation is non-synchronized to improve performance.

It performs quicker than the LinkedListStackImpl version.

There is no maximum capacity which is enforced, nor is there any checks if pop() is executed on an empty stack.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ArrayStackImpl()
          Allocates an ArrayList with a capacity of 100.
 
Method Summary
 E peek()
          Inspect the top-most element without affecting the stack.
 E pop()
          Pops an item off the stack.
 void push(E o)
          Push an item to the stack.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeRange, retainAll, set, size, subList, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
containsAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jawk.util.MyStack
clear, size
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode
 

Constructor Detail

ArrayStackImpl

public ArrayStackImpl()
Allocates an ArrayList with a capacity of 100.

Method Detail

push

public void push(E o)
Push an item to the stack.

Specified by:
push in interface MyStack<E>
Parameters:
o - The item to push onto the stack.

pop

public E pop()
Pops an item off the stack.

Warning: no checks are done in terms of size, etc. If a pop() occurrs on an empty stack, an ArrayIndexOutOfBoundException is thrown.

Specified by:
pop in interface MyStack<E>
Returns:
The top of the stack. The element is subsequently removed from the stack.

peek

public E peek()
Description copied from interface: MyStack
Inspect the top-most element without affecting the stack.

Specified by:
peek in interface MyStack<E>