org.elkoserver.util
Class HashSetMulti<V>

java.lang.Object
  extended by org.elkoserver.util.HashSetMulti<V>
All Implemented Interfaces:
Iterable<V>

public class HashSetMulti<V>
extends Object
implements Iterable<V>

A hash "set" that objects can be added to multiple times. An object must be removed an equal number of times before it disappears. This class is to HashMapMulti as HashSet is to HashMap, but note that it does not truly implement the set abstraction since the number of times a value is entered is significant.


Constructor Summary
HashSetMulti()
          Construct a new, empty set.
 
Method Summary
 void add(V obj)
          Add an object to the set.
 HashSetMulti<V> asUnmodifiable()
          Produce a new set that is a read-only version of this one.
 boolean contains(V obj)
          Test if a given object is a member of the set (i.e., that it has been added more times than it has been removed).
static
<V> HashSetMulti<V>
emptySet()
          Produce an empty set.
 boolean isEmpty()
          Test if this set is empty.
 Iterator<V> iterator()
          Obtain an iterator over the objects in this set (not repeating multiples).
 void remove(V obj)
          Remove an object from the set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashSetMulti

public HashSetMulti()
Construct a new, empty set.

Method Detail

add

public void add(V obj)
Add an object to the set.

Parameters:
obj - The object to add.

asUnmodifiable

public HashSetMulti<V> asUnmodifiable()
Produce a new set that is a read-only version of this one.

Returns:
an unmodifiable view onto this set.

contains

public boolean contains(V obj)
Test if a given object is a member of the set (i.e., that it has been added more times than it has been removed).

Parameters:
obj - The object to test for.
Returns:
true if 'obj' is a member of this set.

emptySet

public static <V> HashSetMulti<V> emptySet()
Produce an empty set.

Returns:
a read-only empty set.

isEmpty

public boolean isEmpty()
Test if this set is empty.

Returns:
true if this set contains no members.

iterator

public Iterator<V> iterator()
Obtain an iterator over the objects in this set (not repeating multiples).

Specified by:
iterator in interface Iterable<V>
Returns:
an iterator over the objects contained by this set. Note that each object that is in the set is returned exactly once, regardless of how many times it has been added.

remove

public void remove(V obj)
Remove an object from the set. Note that the object only really disappears from the set once it has been removed as many times as it was added. Removes in excess of adds are silently ignored.

Parameters:
obj - The object to remove.