org.apache.wicket.util.collections
Class ArrayListStack<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<T>
              extended by org.apache.wicket.util.collections.ArrayListStack<T>
Type Parameters:
T -
All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess

public class ArrayListStack<T>
extends ArrayList<T>

A faster, smaller stack implementation. ArrayListStack is final and unsynchronized (the JDK's methods are synchronized). In addition you can set the initial capacity if you want via the ArrayListStack(int) constructor.

Author:
Jonathan Locke
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ArrayListStack()
          Construct.
ArrayListStack(Collection<T> collection)
          Construct.
ArrayListStack(int initialCapacity)
          Construct.
 
Method Summary
 boolean empty()
          Tests if this stack is empty.
 T peek()
          Looks at the object at the top of this stack without removing it.
 T pop()
          Removes the object at the top of this stack and returns that object.
 void push(T item)
          Pushes an item onto the top of this stack.
 int search(T o)
          Returns the 1-based position where an object is on this stack.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, 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, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

ArrayListStack

public ArrayListStack(int initialCapacity)
Construct.

Parameters:
initialCapacity - Initial capacity of the stack

ArrayListStack

public ArrayListStack()
Construct.


ArrayListStack

public ArrayListStack(Collection<T> collection)
Construct.

Parameters:
collection - The collection to add
Method Detail

push

public final void push(T item)
Pushes an item onto the top of this stack.

Parameters:
item - the item to be pushed onto this stack.

pop

public final T pop()
Removes the object at the top of this stack and returns that object.

Returns:
The object at the top of this stack
Throws:
EmptyStackException - If this stack is empty.

peek

public final T peek()
Looks at the object at the top of this stack without removing it.

Returns:
The object at the top of this stack
Throws:
EmptyStackException - If this stack is empty.

empty

public final boolean empty()
Tests if this stack is empty.

Returns:
true if and only if this stack contains no items; false otherwise.

search

public final int search(T o)
Returns the 1-based position where an object is on this stack. If the object o occurs as an item in this stack, this method returns the distance from the top of the stack of the occurrence nearest the top of the stack; the topmost item on the stack is considered to be at distance 1. The equals method is used to compare o to the items in this stack.

Parameters:
o - the desired object.
Returns:
the 1-based position from the top of the stack where the object is located; the return value -1 indicates that the object is not on the stack.


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.