net.cscott.jutil

Class WorkSet<E>

public class WorkSet<E> extends AbstractSet<E> implements Serializable

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.2 2004/01/13 01:28:37 cananian Exp $

Author: C. Scott Ananian

Constructor Summary
WorkSet()
Creates a new, empty WorkSet with a default capacity and load factor.
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.
<T extends E>WorkSet(Collection<T> c)
Constructs a new WorkSet with the contents of the specified Collection.
Method Summary
booleanadd(E o)
Adds the object to the set and returns true if the element is not already present.
booleanaddFirst(E o)
Adds an element to the front of the (ordered) set and returns true, if the element is not already present in the set.
booleanaddLast(E o)
Adds an element to the end of the (ordered) set and returns true, if the element is not already present in the set.
voidclear()
Removes all elements from the set.
booleancontains(Object o)
Determines if this contains an item.
EgetFirst()
Returns the first element in the ordered set.
EgetLast()
Returns the last element in the ordered set.
booleanisEmpty()
Determines if there are any more items left in this.
Iterator<E>iterator()
Efficient set iterator.
Epeek()
Looks at the object as the top of this WorkSet (treating it as a Stack) without removing it from the set/stack.
Epop()
Removes the item at the top of this WorkSet (treating it as a Stack) and returns that object as the value of this function.
voidpush(E item)
Pushes item onto the top of this WorkSet (treating it as a Stack), if it is not already there.
booleanremove(Object o)
EremoveFirst()
Removes the first element in the ordered set and returns it.
EremoveLast()
Removes the last element in the ordered set and returns it.
intsize()

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 <T extends E> WorkSet(Collection<T> c)
Constructs a new WorkSet with the contents of the specified Collection.

Method Detail

add

public boolean add(E 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.

addFirst

public boolean addFirst(E 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(E 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.

clear

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

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.

getFirst

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

getLast

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

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.

iterator

public Iterator<E> iterator()
Efficient set iterator.

peek

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

pop

public E 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(E 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.

remove

public boolean remove(Object o)

removeFirst

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

removeLast

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

size

public int size()
Copyright © 2003 C. Scott Ananian