harpoon.Util.Collections
Class WorkSet

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractSet
              |
              +--harpoon.Util.Collections.WorkSet
All Implemented Interfaces:
Collection, Set, Worklist

public class WorkSet
extends AbstractSet
implements Worklist

A WorkSet is a Set offering constant-time access to the first/last element inserted, and an iterator whose speed is not dependent on the total capacity of the underlying hashtable.

Conforms to the JDK 1.2 Collections API.

Version:
$Id: WorkSet.java,v 1.3 2002/02/26 22:47:38 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>

Constructor Summary
WorkSet()
          Creates a new, empty WorkSet with a default capacity and load factor.
WorkSet(Collection c)
          Constructs a new WorkSet with the contents of the specified Collection.
WorkSet(int initialCapacity)
          Constructs a new, empty WorkSet with the specified initial capacity and default load factor.
WorkSet(int initialCapacity, float loadFactor)
          Constructs a new, empty WorkSet with the specified initial capacity and the specified load factor.
 
Method Summary
 boolean add(Object o)
          Adds the object to the set and returns true if the element is not already present.
 boolean addFirst(Object o)
          Adds an element to the front of the (ordered) set and returns true, if the element is not already present in the set.
 boolean addLast(Object o)
          Adds an element to the end of the (ordered) set and returns true, if the element is not already present in the set.
 void clear()
          Removes all elements from the set.
 boolean contains(Object o)
          Determines if this contains an item.
 Object getFirst()
          Returns the first element in the ordered set.
 Object getLast()
          Returns the last element in the ordered set.
 boolean isEmpty()
          Determines if there are any more items left in this.
 Iterator iterator()
          Efficient set iterator.
 Object peek()
          Looks at the object as the top of this WorkSet (treating it as a Stack) without removing it from the set/stack.
 Object pop()
          Removes the item at the top of this WorkSet (treating it as a Stack) and returns that object as the value of this function.
 Object pull()
          Removes some item from this and return it (Worklist adaptor method).
 void push(Object item)
          Pushes item onto the top of this WorkSet (treating it as a Stack), if it is not already there.
 boolean remove(Object o)
           
 Object removeFirst()
          Removes the first element in the ordered set and returns it.
 Object removeLast()
          Removes the last element in the ordered set and returns it.
 int size()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, retainAll, toArray, toArray
 

Constructor Detail

WorkSet

public WorkSet()
Creates a new, empty WorkSet with a default capacity and load factor.


WorkSet

public WorkSet(int initialCapacity)
Constructs a new, empty WorkSet with the specified initial capacity and default load factor.


WorkSet

public WorkSet(int initialCapacity,
               float loadFactor)
Constructs a new, empty WorkSet with the specified initial capacity and the specified load factor.


WorkSet

public WorkSet(Collection c)
Constructs a new WorkSet with the contents of the specified Collection.

Method Detail

addFirst

public boolean addFirst(Object o)
Adds an element to the front of the (ordered) set and returns true, if the element is not already present in the set. Makes no change to the set and returns false if the element is already in the set.


addLast

public boolean addLast(Object o)
Adds an element to the end of the (ordered) set and returns true, if the element is not already present in the set. Makes no change to the set and returns false if the element is already in the set.


getFirst

public Object getFirst()
Returns the first element in the ordered set.


getLast

public Object getLast()
Returns the last element in the ordered set.


removeFirst

public Object removeFirst()
Removes the first element in the ordered set and returns it.


removeLast

public Object removeLast()
Removes the last element in the ordered set and returns it.


peek

public Object peek()
Looks at the object as the top of this WorkSet (treating it as a Stack) without removing it from the set/stack.


pull

public Object pull()
Removes some item from this and return it (Worklist adaptor method).
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

pop

public Object pop()
Removes the item at the top of this WorkSet (treating it as a Stack) and returns that object as the value of this function.


push

public void push(Object item)
Pushes item onto the top of this WorkSet (treating it as a Stack), if it is not already there. If the item is already in the set/on the stack, then this method does nothing.
modifies: this
effects: If item is not already an element of this, adds item to this. Else does nothing.

Specified by:
push in interface Worklist

add

public boolean add(Object o)
Adds the object to the set and returns true if the element is not already present. Otherwise makes no change to the set and returns false.

Specified by:
add in interface Set
Overrides:
add in class AbstractCollection

clear

public void clear()
Removes all elements from the set.

Specified by:
clear in interface Set
Overrides:
clear in class AbstractCollection

contains

public boolean contains(Object o)
Determines if this contains an item.
effects: If o is an element of this, returns true. Else returns false.

Specified by:
contains in interface Worklist
Overrides:
contains in class AbstractCollection

isEmpty

public boolean isEmpty()
Determines if there are any more items left in this.
effects: If this has any elements, returns true. Else returns false.

Specified by:
isEmpty in interface Worklist
Overrides:
isEmpty in class AbstractCollection

iterator

public Iterator iterator()
Efficient set iterator.

Specified by:
iterator in interface Set
Specified by:
iterator in class AbstractCollection

remove

public boolean remove(Object o)
Specified by:
remove in interface Set
Overrides:
remove in class AbstractCollection

size

public int size()
Specified by:
size in interface Set
Specified by:
size in class AbstractCollection