harpoon.Util.Collections
Class UniqueStack

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--harpoon.Util.Collections.UniqueVector
                    |
                    +--harpoon.Util.Collections.UniqueStack
All Implemented Interfaces:
Cloneable, Collection, List, Set, Worklist

public class UniqueStack
extends UniqueVector
implements Worklist

The UniqueStack class represents a last-in-first-out stack of unique objects.

Conforms to the JDK 1.2 Collections API.

Version:
$Id: UniqueStack.java,v 1.2 2002/02/25 21:09:15 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
UniqueStack()
          Creates a UniqueStack.
UniqueStack(Collection c)
          Constructs a UniqueStack containing the elements of the specified Collection, in the order they are returned by the collection's iterator in LIFO order.
 
Method Summary
 boolean empty()
          Tests if this stack is empty.
 Object peek()
          Looks at the object at the top of this stack without removing it from the stack.
 Object pop()
          Removes the object at the top of this stack and returns that object as the value of this function.
 Object pull()
          Removes some item from the Worklist and return it.
 void push(Object item)
          Pushes an item onto the top of this stack, if it is unique.
 int search(Object o)
          Returns where an object is on this stack.
 
Methods inherited from class harpoon.Util.Collections.UniqueVector
add, add, addElement, capacity, clear, clone, contains, copyInto, elementAt, elements, ensureCapacity, firstElement, get, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, removeAllElements, removeElement, removeElementAt, set, setElementAt, size, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
addAll, equals, hashCode, iterator, listIterator, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, remove, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface harpoon.Util.Worklist
contains, isEmpty
 
Methods inherited from interface java.util.Set
addAll, containsAll, equals, hashCode, iterator, remove, removeAll, retainAll
 
Methods inherited from interface java.util.List
addAll, containsAll, remove, removeAll, retainAll
 

Constructor Detail

UniqueStack

public UniqueStack()
Creates a UniqueStack.


UniqueStack

public UniqueStack(Collection c)
Constructs a UniqueStack containing the elements of the specified Collection, in the order they are returned by the collection's iterator in LIFO order. That is, the first item returned by the collection iterator will be at the bottom of the stack, and thus last to be popped. Duplicate elements in c are skipped.

Method Detail

push

public void push(Object item)
Pushes an item onto the top of this stack, if it is unique. Otherwise, does nothing.

Specified by:
push in interface Worklist
Parameters:
item - the item to be pushed onto this stack.

pop

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

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

pull

public Object pull()
Description copied from interface: Worklist
Removes some item from the Worklist and return it.
modifies: this
effects: If there exists an Object, item, that is an element of this, removes item from this and returns item. Else does nothing.

Specified by:
pull in interface Worklist

peek

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

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

empty

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

Returns:
true if this stack is empty; false otherwise.

search

public int search(Object o)
Returns where an object is on this stack.

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