wyvern.util
Class ConcurrentHashSet

java.lang.Object
  extended bywyvern.util.ConcurrentHashSet
All Implemented Interfaces:
java.util.Collection, java.util.Set

public class ConcurrentHashSet
extends java.lang.Object
implements java.util.Set

A HashSet that can be accessed and modified from multiple threads.

Version:
1.0, Jul 22, 2003
Author:
Steve Yegge

Constructor Summary
ConcurrentHashSet()
          Constructs a new ConcurrentHashSet
 
Method Summary
 boolean add(java.lang.Object obj)
          Adds the specified element to this set if it is not already present.
 boolean addAll(java.util.Collection c)
          Adds all of the elements in the specified collection to this set if they're not already present (optional operation).
 void clear()
          Removes all the elements from the set.
 boolean contains(java.lang.Object obj)
          Returns true if the map contains the specified object.
 boolean containsAll(java.util.Collection c)
          Returns true if the set contains all of the elements of the specified collection.
 boolean equals(java.lang.Object obj)
          Returns true if these sets are equal.
 int hashCode()
          Returns the hash code value for this set.
 boolean isEmpty()
          Returns true if this set contains no elements.
 java.util.Iterator iterator()
          Returns an iterator over the elements of this set.
static void main(java.lang.String[] args)
          Tests the operation of the set.
 boolean remove(java.lang.Object obj)
          Removes an object from the set.
 boolean removeAll(java.util.Collection c)
          Removes from this set all of its elements that are contains in the specified collection.
 boolean retainAll(java.util.Collection c)
          Retains only the elements in this set that are contained in the specified collection.
 int size()
          Returns the number of elements in this set (its cardinality)
 java.lang.Object[] toArray()
          Returns an array containing a snapshot of the elements of the set at some point in time while the array is being constructed.
 java.lang.Object[] toArray(java.lang.Object[] a)
          Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.
 java.lang.String toString()
          Returns debugging representation of this set.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConcurrentHashSet

public ConcurrentHashSet()
Constructs a new ConcurrentHashSet

Method Detail

add

public boolean add(java.lang.Object obj)
Adds the specified element to this set if it is not already present.

Specified by:
add in interface java.util.Set
Returns:
true if it was added, false if already present (not guaranteed to be accurate - use a normal HashSet if you require this always to be correct)

addAll

public boolean addAll(java.util.Collection c)
Adds all of the elements in the specified collection to this set if they're not already present (optional operation). If the specified collection is also a set, the addAll operation effectively modifies this set so that its value is the union of the two sets. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress

Specified by:
addAll in interface java.util.Set

clear

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

Specified by:
clear in interface java.util.Set

contains

public boolean contains(java.lang.Object obj)
Returns true if the map contains the specified object.

Specified by:
contains in interface java.util.Set

containsAll

public boolean containsAll(java.util.Collection c)
Returns true if the set contains all of the elements of the specified collection.

Specified by:
containsAll in interface java.util.Set

equals

public boolean equals(java.lang.Object obj)
Returns true if these sets are equal.

Specified by:
equals in interface java.util.Set
Returns:
true if the passed object is also a Set, the two sets have the same size, and every member of the specified set is contained in this set.

hashCode

public int hashCode()
Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set, where the hashcode of a null element is defined to be zero. This ensures that s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for any two sets s1 and s2, as required by the general contract of the Object.hashCode method.

Specified by:
hashCode in interface java.util.Set

isEmpty

public boolean isEmpty()
Returns true if this set contains no elements.

Specified by:
isEmpty in interface java.util.Set

iterator

public java.util.Iterator iterator()
Returns an iterator over the elements of this set.

Specified by:
iterator in interface java.util.Set

remove

public boolean remove(java.lang.Object obj)
Removes an object from the set.

Specified by:
remove in interface java.util.Set

removeAll

public boolean removeAll(java.util.Collection c)
Removes from this set all of its elements that are contains in the specified collection.

Specified by:
removeAll in interface java.util.Set
Returns:
an undefined boolean value - don't rely on it

retainAll

public boolean retainAll(java.util.Collection c)
Retains only the elements in this set that are contained in the specified collection.

Specified by:
retainAll in interface java.util.Set
Returns:
an undefined boolean value - don't rely on it

size

public int size()
Returns the number of elements in this set (its cardinality)

Specified by:
size in interface java.util.Set
Returns:
the number of objects in the set

toArray

public java.lang.Object[] toArray()
Returns an array containing a snapshot of the elements of the set at some point in time while the array is being constructed.

Specified by:
toArray in interface java.util.Set

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Specified by:
toArray in interface java.util.Set

toString

public java.lang.String toString()
Returns debugging representation of this set.


main

public static void main(java.lang.String[] args)
Tests the operation of the set.