com.hedgehog.utility
Class IntegerSet

java.lang.Object
  extended by com.hedgehog.HObject
      extended by com.hedgehog.utility.IntegerSet
All Implemented Interfaces:
java.lang.Comparable, java.util.Comparator
Direct Known Subclasses:
IDSet

public class IntegerSet
extends HObject

Title: IntegerSet - set specifically for integers.

Description: Stores a set of integers.

This class is identical to Set except that all comparisons are performed on integer values and not object references.

Useful for comparing integer IDs in class ID.

Copyright: Copyright (c) Hedgehog Software 2007-2009.

Company: Hedgehog Software.

Since:
1.0
Version:
1.1
See Also:
HSet

Field Summary
protected  java.util.HashSet<HInteger> mSet
          Set of HInteger elements.
 
Fields inherited from class com.hedgehog.HObject
mID, mName
 
Constructor Summary
IntegerSet()
          Constructor.
IntegerSet(java.util.HashSet<HInteger> elements)
          Constructor.
IntegerSet(HInteger element)
          Constructor.
IntegerSet(int element)
          Constructor.
IntegerSet(int[] elements)
          Constructor.
IntegerSet(IntegerSet object)
          Copy constructor.
IntegerSet(java.util.Vector<HInteger> elements)
          Constructor.
 
Method Summary
 boolean add(HInteger element)
          Adds the specified ID, provided it is not already a member.
 boolean add(int element)
          Adds the specified ID, provided it is not already a member.
 IntegerSet difference(IntegerSet s)
          Returns the difference A-B: the set containing all elements that are in A but not in B.
 void differenceFrom(IntegerSet s)
          Difference A-B: the set containing all elements that are in A (this set) but not in B (s).
 java.util.HashSet<HInteger> getElements()
          Returns the set elements.
 IntegerSet intersection(IntegerSet s)
          Returns the intersection A&B: the set containing all elements that are both in A and B.
 void intersectionWith(IntegerSet s)
          Intersection A&B: the set containing all elements that are both in A and B.
 boolean isEmpty()
          Tests whether or not this set is empty.
 boolean isMember(HInteger element)
          Tests whether or not the specified HInteger object is an element of this set.
 boolean isMember(int element)
          Tests whether or not the specified element is a member of this set.
 int numberElements()
          Returns the number of set elements.
 boolean remove(int element)
          Removes the specified
 void removeAll()
          Removes all elements from this set.
 int representativeElement()
          Returns a representative element of this set; ie the first element.
 boolean sameSet(IntegerSet s)
          Tests whether or not the specified set is identical to this set.
 void setElements(java.util.HashSet<HInteger> elements)
          Sets the set elements.
 int size()
          Equivalent to numberElements(), in that it returns the size of this set.
 boolean subsetOft(IntegerSet s)
          Tests whether or not the specified set is a subset of this set.
 IntegerSet symmetricDifference(IntegerSet s)
          Returns the symmetric difference; A^B: the union of A-B and B-A.
 int[] toArray()
          Converts this set o a 1D Java array.
 java.lang.String toString()
          Returns a String representation of a Set object.
 IntegerSet union(IntegerSet s)
          Returns the uunion A|B: the set containing all elements in A and B (without duplication).
 void unionWith(IntegerSet s)
          Union A|B: the set containing all elements in A and B (without duplication).
 
Methods inherited from class com.hedgehog.HObject
clone, compare, compareTo, copy, equals, getID, getName, hashCode, hasID, hasName, setID, setName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

mSet

protected java.util.HashSet<HInteger> mSet
Set of HInteger elements.

Constructor Detail

IntegerSet

public IntegerSet()
Constructor. Creates a new non-null empty set.


IntegerSet

public IntegerSet(int element)
Constructor. Creates a new set having the specified element.

Parameters:
element - Set element.

IntegerSet

public IntegerSet(HInteger element)
Constructor. Creates a new set having the specified element.

Parameters:
element - Set element.

IntegerSet

public IntegerSet(java.util.HashSet<HInteger> elements)
Constructor. Creates a new set having the specified elements.

Parameters:
elements - Hash set of elements.

IntegerSet

public IntegerSet(java.util.Vector<HInteger> elements)
Constructor. Creates a new set from the specified vector of elements.

Parameters:
elements - Vector of elements.

IntegerSet

public IntegerSet(int[] elements)
Constructor. Creates a new set from the specified 1D Java array of elements.

Parameters:
elements - Array of elements.

IntegerSet

public IntegerSet(IntegerSet object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

getElements

public java.util.HashSet<HInteger> getElements()
Returns the set elements.

Returns:
Set elements.

setElements

public void setElements(java.util.HashSet<HInteger> elements)
Sets the set elements.

Parameters:
elements - New set elements.

add

public boolean add(int element)
Adds the specified ID, provided it is not already a member.

Parameters:
element - Element to add.
Returns:
Logical-true if the specified object is added, else logical-false.

add

public boolean add(HInteger element)
Adds the specified ID, provided it is not already a member.

Parameters:
element - Element to add.
Returns:
Logical-true if the specified object is added, else logical-false.

remove

public boolean remove(int element)
Removes the specified

Parameters:
element - Element to remove.
Returns:
Logical-true if elemen is removed, else logical-false.

removeAll

public void removeAll()
Removes all elements from this set.


isMember

public boolean isMember(int element)
Tests whether or not the specified element is a member of this set.

Parameters:
element - Element to test.
Returns:
Logical-true if element is a member of this set, else logical-false.

isMember

public boolean isMember(HInteger element)
Tests whether or not the specified HInteger object is an element of this set.

Parameters:
element - Object element to test.
Returns:
Logical-true if the specified HInteger object is an element of this set, else logical-false.

isEmpty

public boolean isEmpty()
Tests whether or not this set is empty.

Returns:
Logical-true if this set is empty, else logical-false.

numberElements

public int numberElements()
Returns the number of set elements.

Returns:
Number of set elements.

size

public int size()
Equivalent to numberElements(), in that it returns the size of this set.

Returns:
Number of elements in this set.

differenceFrom

public void differenceFrom(IntegerSet s)
Difference A-B: the set containing all elements that are in A (this set) but not in B (s).

Parameters:
s - Other set B.

intersectionWith

public void intersectionWith(IntegerSet s)
Intersection A&B: the set containing all elements that are both in A and B.

Parameters:
s - Other set B.

subsetOft

public boolean subsetOft(IntegerSet s)
Tests whether or not the specified set is a subset of this set.

Parameters:
s - Subset.
Returns:
Logical-true if s is a subset (ie; all elements of s are members of this set), else logicla-false.

sameSet

public boolean sameSet(IntegerSet s)
Tests whether or not the specified set is identical to this set.

Parameters:
s - Other set.
Returns:
Logical-true if s is identical to this set, else logical-false.

representativeElement

public int representativeElement()
                          throws InvalidObjectException
Returns a representative element of this set; ie the first element.

Returns:
First element, representative of this set. If this set is null or empty then null is returned to indicate that this set has no representative element.
Throws:
InvalidObjectException - Thrown if mSet is null or empty.

unionWith

public void unionWith(IntegerSet s)
Union A|B: the set containing all elements in A and B (without duplication). Adds all elements of set s to this set, provided that are not already members.

Parameters:
s - Other set.

union

public IntegerSet union(IntegerSet s)
Returns the uunion A|B: the set containing all elements in A and B (without duplication). For example, the union of the sets {1,2,3} and {3,4} is {1,2,3,4}.

Parameters:
s - Other set.
Returns:
Union of this set and s.

intersection

public IntegerSet intersection(IntegerSet s)
Returns the intersection A&B: the set containing all elements that are both in A and B. For example, the intersection of the sets {1,2,3} and {3,4} is {3}.

Parameters:
s - Other set.
Returns:
Intersection of this set and s.

difference

public IntegerSet difference(IntegerSet s)
Returns the difference A-B: the set containing all elements that are in A but not in B. For example, the difference of the sets {1,2,3} and {3,4} is {1,2}.

Parameters:
s - Other set.
Returns:
Difference of this set and s.

symmetricDifference

public IntegerSet symmetricDifference(IntegerSet s)
Returns the symmetric difference; A^B: the union of A-B and B-A. The symmetric difference of two sets is the set of elements which are in one of either set, but not in both. For example, the symmetric difference of the sets {1,2,3} and {3,4} is {1,2,4}.

Parameters:
s - Other set.
Returns:
Symmetric difference of this set and s.

toString

public java.lang.String toString()
Returns a String representation of a Set object.

Overrides:
toString in class java.lang.Object
Returns:
A String representation of a Set object.

toArray

public int[] toArray()
Converts this set o a 1D Java array.

Returns:
A 1D Java array of this set's elements.