weiss.util
Class HashSet<AnyType>

java.lang.Object
  extended by weiss.util.AbstractCollection<AnyType>
      extended by weiss.util.HashSet<AnyType>
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<AnyType>, Collection<AnyType>, Set<AnyType>

public class HashSet<AnyType>
extends AbstractCollection<AnyType>
implements Set<AnyType>

HashSet implementation. Matches are based on equals; and hashCode must be consistently defined.

See Also:
Serialized Form

Constructor Summary
HashSet()
          Construct an empty HashSet.
HashSet(Collection<? extends AnyType> other)
          Construct a HashSet from any collection.
 
Method Summary
 boolean add(AnyType x)
          Adds an item to this collection.
 void clear()
          Change the size of this collection to zero.
 boolean contains(java.lang.Object x)
          Tests if some item is in this collection.
 AnyType getMatch(AnyType x)
          This method is not part of standard Java.
 Iterator<AnyType> iterator()
          Obtains an Iterator object used to traverse the collection.
 boolean remove(java.lang.Object x)
          Removes an item from this collection.
 int size()
          Returns the number of items in this collection.
 
Methods inherited from class weiss.util.AbstractCollection
equals, hashCode, isEmpty, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface weiss.util.Collection
isEmpty, toArray, toArray
 

Constructor Detail

HashSet

public HashSet()
Construct an empty HashSet.


HashSet

public HashSet(Collection<? extends AnyType> other)
Construct a HashSet from any collection.

Method Detail

size

public int size()
Returns the number of items in this collection.

Specified by:
size in interface Collection<AnyType>
Returns:
the number of items in this collection.

getMatch

public AnyType getMatch(AnyType x)
This method is not part of standard Java. Like contains, it checks if x is in the set. If it is, it returns the reference to the matching object; otherwise it returns null.

Specified by:
getMatch in interface Set<AnyType>
Parameters:
x - the object to search for.
Returns:
if contains(x) is false, the return value is null; otherwise, the return value is the object that causes contains(x) to return true.

contains

public boolean contains(java.lang.Object x)
Tests if some item is in this collection.

Specified by:
contains in interface Collection<AnyType>
Overrides:
contains in class AbstractCollection<AnyType>
Parameters:
x - any object.
Returns:
true if this collection contains an item equal to x.

add

public boolean add(AnyType x)
Adds an item to this collection.

Specified by:
add in interface Collection<AnyType>
Overrides:
add in class AbstractCollection<AnyType>
Parameters:
x - any object.
Returns:
true if this item was added to the collection.

remove

public boolean remove(java.lang.Object x)
Removes an item from this collection.

Specified by:
remove in interface Collection<AnyType>
Overrides:
remove in class AbstractCollection<AnyType>
Parameters:
x - any object.
Returns:
true if this item was removed from the collection.

clear

public void clear()
Change the size of this collection to zero.

Specified by:
clear in interface Collection<AnyType>
Overrides:
clear in class AbstractCollection<AnyType>

iterator

public Iterator<AnyType> iterator()
Obtains an Iterator object used to traverse the collection.

Specified by:
iterator in interface java.lang.Iterable<AnyType>
Specified by:
iterator in interface Collection<AnyType>
Returns:
an iterator positioned prior to the first element.