org.apache.commons.collections
Class ArrayStack

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.ArrayList
                    |
                    +--org.apache.commons.collections.ArrayStack
All Implemented Interfaces:
Cloneable, Collection, List, Serializable

public class ArrayStack
extends ArrayList

An implementation of the Stack API that is based on an ArrayList instead of a Vector, so it is not synchronized to protect against multi-threaded access. The implementation is therefore operates faster in environments where you do not need to worry about multiple thread contention.

Version:
$Revision: 1.3 $ $Date: 2001/05/04 16:33:18 $
Author:
Craig R. McClanahan
See Also:
Stack, Serialized Form

Constructor Summary
ArrayStack()
           
 
Method Summary
 boolean empty()
          Return true if this stack is currently empty.
 Object peek()
          Return the top item off of this stack without removing it.
 Object peek(int n)
          Return the n'th item down (zero-relative) from the top of this stack without removing it.
 Object pop()
          Pop the top item off of this stack and return it.
 Object push(Object item)
          Push a new item onto the top of this stack.
 int search(Object o)
          Return the one-based position of the distance from the top that the specified object exists on this stack, where the top-most element is considered to be at distance 1.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList
 

Constructor Detail

ArrayStack

public ArrayStack()
Method Detail

empty

public boolean empty()
Return true if this stack is currently empty.

peek

public Object peek()
            throws EmptyStackException
Return the top item off of this stack without removing it.
Throws:
EmptyStackExceptino - if the stack is empty

peek

public Object peek(int n)
            throws EmptyStackException
Return the n'th item down (zero-relative) from the top of this stack without removing it.
Parameters:
n - Number of items down to go
Throws:
EmptyStackException - if there are not enough items on the stack to satisfy this request

pop

public Object pop()
           throws EmptyStackException
Pop the top item off of this stack and return it.
Throws:
EmptyStackException - if the stack is empty

push

public Object push(Object item)
Push a new item onto the top of this stack. The pushed item is also returned.
Parameters:
item - Item to be added

search

public int search(Object o)
Return the one-based position of the distance from the top that the specified object exists on this stack, where the top-most element is considered to be at distance 1. If the object is not present on the stack, return -1 instead. The equals() method is used to compare to the items in this stack.
Parameters:
o - Object to be searched for


Copyright © 2001 Apache Software Foundation. Documenation generated July 14 2001.