scale.common
Class Stack<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<T>
              extended by scale.common.Vector<T>
                  extended by scale.common.Stack<T>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, java.util.RandomAccess

public class Stack<T>
extends Vector<T>
implements java.lang.Cloneable

Implement our own Stack class that is un-synchronized and allows us to collect statictics on the number of Stacks in use.

$Id: Stack.java,v 1.4 2007-10-04 19:58:11 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Stack()
          Constructs an empty vector.
Stack(int initialCapacity)
          Constructs an empty vector with the specified initial capacity.
Stack(int initialCapacity, int dummy)
          Constructs an empty vector with the specified initial capacity.
Stack(Stack<T> stk)
          Constructs an empty vector.
 
Method Summary
 Stack<T> clone()
          Returns a clone of this vector.
 boolean empty()
          Returns true if and only if this stack contains no items; false otherwise.
 T peek()
          Returns the object at the top of this stack without removing it from the stack.
 T peekd()
          Returns the object next to the top of this stack without removing it from the stack.
 T pop()
          Removes the object at the top of this stack and returns that object as the value of this function.
 T push(T element)
          Pushes an item onto the top of this stack.
 int search(java.lang.Object o)
          Returns the 1-based position where an object is on this stack.
 
Methods inherited from class scale.common.Vector
addElement, addVectors, addVectors, addVectors, elementAt, elements, firstElement, insertElementAt, lastElement, removeAllElements, removeElement, removeElementAt, reverse, setElementAt, setSize
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, 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

Stack

public Stack(int initialCapacity)
Constructs an empty vector with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the vector.

Stack

public Stack(int initialCapacity,
             int dummy)
Constructs an empty vector with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the vector.

Stack

public Stack()
Constructs an empty vector.


Stack

public Stack(Stack<T> stk)
Constructs an empty vector.

Method Detail

clone

public Stack<T> clone()
Returns a clone of this vector.

Overrides:
clone in class Vector<T>

pop

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


push

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


peek

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


peekd

public T peekd()
Returns the object next to the top of this stack without removing it from the stack.


empty

public final boolean empty()
Returns true if and only if this stack contains no items; false otherwise.


search

public final int search(java.lang.Object 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.