org.openquark.cal.util
Class ArrayStack<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<E>
org.openquark.cal.util.ArrayStack<E>
- All Implemented Interfaces:
- Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess
public class ArrayStack<E>
- extends ArrayList<E>
A simple stack implementation based on ArrayList. It is faster for
single-threaded use than Stack which is thread-safe.
- Author:
- Joseph Wong, Bo Ilic
- See Also:
- Serialized Form
|
Method Summary |
boolean |
empty()
|
static
|
make()
|
E |
peek()
|
E |
peek(int index)
|
E |
pop()
|
void |
popN(int n)
Pops n elements off the stack. |
void |
push(E e)
Unlike java.util.Stack.push, this method does not return its argument. |
int |
search(E e)
|
| 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 |
ArrayStack
protected ArrayStack()
make
public static <E> ArrayStack<E> make()
push
public final void push(E e)
- Unlike java.util.Stack.push, this method does not return its argument.
This is a small micro-optimization.
- Parameters:
e - adds the element 'e' to the top of the stack
pop
public final E pop()
- Returns:
- returns and removes the top element of the stack
- Throws:
EmptyStackException - if the stack is empty
popN
public final void popN(int n)
- Pops n elements off the stack.
- Parameters:
n - number of elements to pop
- Throws:
EmptyStackException - if there are not enough elements to pop
peek
public final E peek()
- Returns:
- returns the top element of the stack, without removing it
- Throws:
EmptyStackException - if the stack is empty
peek
public final E peek(int index)
- Parameters:
index - the zero-based index of an element from the top of the stack
- Returns:
- returns the element at the given index from the top of the stack, without removing it
- Throws:
EmptyStackException - if the stack does not have enough elements to satisfy this request.
empty
public final boolean empty()
- Returns:
- true iff the stack is empty
search
public final int search(E e)
- Parameters:
e - element to find. Can be null.
- Returns:
- the 1-based position of 'e' on the stack, or -1 if 'e' is not on the stack.
Copyright © 2007 Business Objects. All rights reserved.