FileDocCategorySizeDatePackage
ArrayListStack.javaAPI DocGlassfish v2 API5178Fri May 04 22:32:10 BST 2007com.sun.enterprise.util.collection

ArrayListStack

public class ArrayListStack extends Object
The ArrayListStack class represents a last-in-first-out (LIFO) stack of objects. It encapsulates class ArrayList with four operations that allow a list to be treated as a stack. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, and a method to test for whether the stack is empty

When a stack is first created, it contains no items.

author
Darpan Dinker, $Author: tcfujii $
version
$Revision: 1.4 $ on $Date: 2007/05/05 05:32:09 $

Fields Summary
private int
curIndex
private ArrayList
list
Constructors Summary
public ArrayListStack(int size)
Creates a stack with the given initial size

        curIndex = 0;
        list = new ArrayList(size);
    
public ArrayListStack()
Creates a stack with a default size

        this(20);
    
Methods Summary
public booleanempty()
Tests if this stack is empty.

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

        return curIndex == 0;
    
public java.lang.Objectpeek()
Looks at the object at the top of this stack without removing it from the stack.

return
the object at the top of this stack (the last item of the ArrayList object). Null if stack is empty.

        Object top = null;
        if (curIndex > 0) {
            top = list.get(curIndex - 1);
        }
        return top;
    
public java.lang.Objectpop()
Removes the object at the top of this stack and returns that object as the value of this function.

return
The object at the top of this stack (the last item of the ArrayList object). Null if stack is empty.

        if (curIndex > 0) {
            curIndex -= 1;
            return list.remove(curIndex);
        }
        return null;
    
public voidpush(java.lang.Object obj)
Pushes an item onto the top of this stack. This method will internally add elements to the ArrayList if the stack is full.

param
obj the object to be pushed onto this stack.
see
java.util.ArrayList#add

        list.add(curIndex, obj);
        curIndex += 1;
    
public intsize()
Provides the current size of the stack.

return
int return the current size.

        return curIndex;