mathCollection
Class MathCollections

java.lang.Object
  extended bymathCollection.MathCollections

public final class MathCollections
extends java.lang.Object

This class consists exclusively of static methods that return mathematical collections. It contains "wrappers", which return a new synchronized mathematical collection backed by a specified collection. The methods of this class all throw a NullPointerException if the mathematical collections provided to them are null.

See Also:
MathCollections.SynchronizedMathSet, SetOfSets, Multiset

Nested Class Summary
(package private) static class MathCollections.SynchronizedMathSet
           
(package private) static class MathCollections.SynchronizedMultiset
           
(package private) static class MathCollections.SynchronizedSetOfSets
           
 
Constructor Summary
private MathCollections()
           
 
Method Summary
static MathSet synchronizedMathSet(MathSet ms)
          Returns a synchronized (thread-safe) mathematical set backed by the specified mathematical set.
static MathSet synchronizedMathSet(MathSet ms, java.lang.Object mutex)
          Same behavior as synchronizedMathSet(MathSet), but the mutex that is blocked by method calls can be specified.
static Multiset synchronizedMultiset(Multiset mus)
          Returns a synchronized (thread-safe) multiset backed by the specified multiset.
static Multiset synchronizedMultiset(Multiset mus, java.lang.Object mutex)
          Same behavior as synchronizedMultiset(Multiset), but the mutex that is blocked by method calls can be specified.
static SetOfSets synchronizedSetOfSets(SetOfSets sos)
          Returns a synchronized (thread-safe) set of sets backed by the specified set of sets.
static SetOfSets synchronizedSetOfSets(SetOfSets sos, java.lang.Object mutex)
          Same behavior as synchronizedSetOfSets(SetOfSets), but the mutex that is blocked by method calls can be specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MathCollections

private MathCollections()
Method Detail

synchronizedMathSet

public static MathSet synchronizedMathSet(MathSet ms)
Returns a synchronized (thread-safe) mathematical set backed by the specified mathematical set. In order to guarantee serial access, it is critical that all access to the backing mathematical set is accomplished through the returned mathematical set.

It is imperative that the user manually synchronize on the returned mathematical set when iterating over it:

  MathSet ms = MathCollections.synchronizedMathSet(new HashMathSet());
      ...
  synchronized (ms) {
      Iterator i = ms.iterator(); // Must be in the synchronized block
      while (i.hasNext())
          foo(i.next());
  }
 
Failure to follow this advice may result in non-deterministic behavior.

The returned mathematical set will be serializable if the specified mathematical set is serializable.

Parameters:
ms - the mathematical set to be "wrapped" in a synchronized mathematical set.
Returns:
a synchronized view of the specified mathematical set.
See Also:
synchronizedMathSet(MathSet, java.lang.Object)

synchronizedMathSet

public static MathSet synchronizedMathSet(MathSet ms,
                                          java.lang.Object mutex)
Same behavior as synchronizedMathSet(MathSet), but the mutex that is blocked by method calls can be specified.

Parameters:
ms - the mathematical set to be "wrapped" in a synchronized mathematical set.
mutex - object to be blocked by method calls.
Returns:
a synchronized view of the specified mathematical set.
See Also:
synchronizedMathSet(MathSet)

synchronizedSetOfSets

public static SetOfSets synchronizedSetOfSets(SetOfSets sos)
Returns a synchronized (thread-safe) set of sets backed by the specified set of sets. In order to guarantee serial access, it is critical that all access to the backing set of sets is accomplished through the returned set of sets.

It is imperative that the user manually synchronize on the returned set of sets when iterating over it:

  SetOfSets sos = MathCollections.synchronizedSetOfSets(new HashSetOfSets());
      ...
  synchronized (sos) {
      Iterator i = sos.iterator(); // Must be in the synchronized block
      while (i.hasNext())
          foo(i.next());
  }
 
Failure to follow this advice may result in non-deterministic behavior.

The returned set of sets will be serializable if the specified set of sets is serializable.

Parameters:
sos - the set of sets to be "wrapped" in a synchronized set of sets.
Returns:
a synchronized view of the specified set of sets.
See Also:
synchronizedSetOfSets(SetOfSets, java.lang.Object)

synchronizedSetOfSets

public static SetOfSets synchronizedSetOfSets(SetOfSets sos,
                                              java.lang.Object mutex)
Same behavior as synchronizedSetOfSets(SetOfSets), but the mutex that is blocked by method calls can be specified.

Parameters:
sos - the set of sets to be "wrapped" in a synchronized set of sets.
mutex - object to be blocked by method calls.
Returns:
a synchronized view of the specified set of sets.
See Also:
synchronizedSetOfSets(SetOfSets)

synchronizedMultiset

public static Multiset synchronizedMultiset(Multiset mus)
Returns a synchronized (thread-safe) multiset backed by the specified multiset. In order to guarantee serial access, it is critical that all access to the backing multiset is accomplished through the returned multiset.

It is imperative that the user manually synchronize on the returned multiset when iterating over it:

  Multiset mus = MathCollections.synchronizedMultiset(new HashMultiset());
      ...
  synchronized (mus) {
      Iterator i = mus.iterator(); // Must be in the synchronized block
      while (i.hasNext())
          foo(i.next());
  }
 
Failure to follow this advice may result in non-deterministic behavior.

The returned multiset will be serializable if the specified multiset is serializable.

Parameters:
mus - the multiset to be "wrapped" in a synchronized multiset.
Returns:
a synchronized view of the specified multiset.
See Also:
synchronizedMultiset(Multiset, java.lang.Object)

synchronizedMultiset

public static Multiset synchronizedMultiset(Multiset mus,
                                            java.lang.Object mutex)
Same behavior as synchronizedMultiset(Multiset), but the mutex that is blocked by method calls can be specified.

Parameters:
mus - the multiset to be "wrapped" in a synchronized multiset.
mutex - object to be blocked by method calls.
Returns:
a synchronized view of the specified multiset.
See Also:
synchronizedMultiset(Multiset)