mathCollection
Class AbstractMathSet

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended bymathCollection.AbstractMathSet
All Implemented Interfaces:
java.util.Collection, MathSet, java.util.Set
Direct Known Subclasses:
HashMathSet

public abstract class AbstractMathSet
extends java.util.AbstractSet
implements MathSet

This class provides a skeletal implementation of the MathSet interface to minimize the effort required to implement this interface.

See Also:
Set, AbstractSet, HashMathSet

Constructor Summary
AbstractMathSet()
           
 
Method Summary
 int hashCode()
          Returns the hash code value for this mathematical set.
 boolean isDisjoint(java.util.Set s)
          Returns true if this mathematical set has no common elements with the specified set.
 boolean isSubset(java.util.Set s)
          Returns true if this mathematical set is a subset of the specified set.
 boolean isSuperset(java.util.Set s)
          Returns true if this mathematical set is a superset of the specified set.
 java.lang.String toString()
          Returns a string representation of this mathematical set.
 
Methods inherited from class java.util.AbstractSet
equals, removeAll
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface mathCollection.MathSet
difference, fixedSizeSubsets, intersection, powerSet, symmetricDifference, union
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

AbstractMathSet

public AbstractMathSet()
Method Detail

hashCode

public int hashCode()
Returns the hash code value for this mathematical set. To get the hash code of this mathematical set, new hash code values for every element of this mathematical set are calculated from a polynomial of 3rd order and finally summed up. This ensures that s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for any two mathematical sets s1 and s2, as required by the general contract of Object.hashCode().

Specified by:
hashCode in interface java.util.Set
Returns:
the hash code value for this mathematical set.

toString

public java.lang.String toString()
Returns a string representation of this mathematical set. The string representation consists of a list of the set's elements in the order they are returned by its iterator, enclosed in curly brackets ("{}"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by Object.toString().

Returns:
a string representation of this mathematical set.

isSuperset

public boolean isSuperset(java.util.Set s)
Returns true if this mathematical set is a superset of the specified set. That is, if all elements of the specified set are also present in this mathematical set.

This implementation first compares the sizes of this mathematical set and the specified set by invoking the size method on each. If this mathematical set is bigger than the specified set then each element of the specified set is checked for presence in this mathematical set. Otherwise, false is returned.

Specified by:
isSuperset in interface MathSet
Parameters:
s - set to be checked for being a subset.
Returns:
true if this mathematical set is a superset of the specifed set, false otherwise.
See Also:
isSubset(Set)

isSubset

public boolean isSubset(java.util.Set s)
Returns true if this mathematical set is a subset of the specified set. That is, if all elements of this mathematical set are also present in the specified set.

This implementation first compares the sizes of this mathematical set and the specified set by invoking the size method on each. If this mathematical set is smaller than the specified set then the intersection of this mathematical set with the specified set is calculated. If the intersection has as many elements as this mathematical set then true is returned, false otherwise.

Specified by:
isSubset in interface MathSet
Parameters:
s - set to be checked for being a superset.
Returns:
true if this mathematical set is a subset of the specifed set, false otherwise.
See Also:
isSuperset(Set)

isDisjoint

public boolean isDisjoint(java.util.Set s)
Returns true if this mathematical set has no common elements with the specified set.

This implementation determines which is the smaller of this set and the specified set by invoking the size() method on each. If this set has fewer elements, then the implementation iterates over this set, checking each element returned by the iterator in turn to see if it is contained in the specified set. If it is so contained, false is returned. If the specified set has fewer elements, then the implementation iterates over the specified set, returning false if it finds a common element.

Specified by:
isDisjoint in interface MathSet
Parameters:
s - set to be checked for common elements.
Returns:
true if this mathematical set has no common elements with the specifed set, false otherwise.