diff options
Diffstat (limited to 'projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSet.java')
| -rw-r--r-- | projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSet.java | 319 |
1 files changed, 143 insertions, 176 deletions
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSet.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSet.java index 5318fe8..38a7ec6 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSet.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSet.java @@ -26,187 +26,154 @@ import java.util.Set; import java.util.Vector; /** -* A pure java implementation of NSSet that -* implements Set for greater java interoperability. -* -* @author michael@mpowers.net -* @author $Author: cgruber $ -* @version $Revision: 893 $ -*/ -public class NSSet extends HashSet -{ - /** - * Default constructor. - */ - public NSSet () - { - super(); - } - - /** - * Constructs a NSSet containing the objects - * in the specified collection. - */ - public NSSet ( Collection aCollection ) - { - super( aCollection ); - } - - /** - * Constructs a NSSet containing only - * the specified object. - */ - public NSSet ( Object anObject ) - { - super(); - add( anObject ); - } - - /** - * Constructs a NSSet containing the objects - * in the specified array. - */ - public NSSet ( Object[] anObjectArray ) - { - super(); - for ( int i = 0; i < anObjectArray.length; i++ ) - { - add( anObjectArray[i] ); - } - } - - /** - * Returns an NSArray containing all objects in the set. - */ - public NSArray allObjects () - { - return new NSArray( this ); - } - - /** - * - */ - public Object anyObject () - { - throw new RuntimeException( "Not implemented yet." ); - } - - /** - * Returns whether this set contains the - * specified object. - */ - public boolean containsObject ( Object anObject ) - { - return contains( anObject ); - } - - /** - * Returns the number of elements in this set. - */ - public int count () - { - return size(); - } - - /** - * Returns whether this set has one or more - * elements in common with the specified set. - */ - public boolean intersectsSet ( Set aSet ) - { - Iterator it = aSet.iterator(); - while ( it.hasNext() ) - { - if ( this.containsObject( it.next() ) ) - { - return true; - } - } - return false; - - } - - /** - * Returns whether this set contains the - * same object as the specified set. - */ - public boolean isEqualToSet ( Set aSet ) - { - return equals( aSet ); - } - - /** - * Returns whether this set is a subset - * of the specified set. - */ - public boolean isSubsetOfSet ( Set aSet ) - { - return aSet.containsAll( this ); - } - - /** - * - */ - public Object member ( Object anObject ) - { - throw new RuntimeException( "Not implemented yet." ); - } - - /** - * Returns an enumerator over the objects - * in this set. - */ - public Enumeration objectEnumerator () - { - return new Vector( this ).elements(); - } - - /** - * Returns a set that is the intersection - * of this set and the specified set. - */ - public NSSet setByIntersectingSet ( Set aSet ) - { - NSSet result = new NSSet( this ); - result.retainAll( aSet ); - return result; - } - - /** - * Returns a set that contains all elements - * in this set that are not in the specified set. - */ - public NSSet setBySubtractingSet ( Set aSet ) - { - NSSet result = new NSSet( this ); - result.removeAll( aSet ); - return result; - } - - /** - * Returns a set that is the union - * of this set and the specified set. - */ - public NSSet setByUnioningSet ( Set aSet ) - { - NSSet result = new NSSet( this ); - result.addAll( aSet ); - return result; - } - + * A pure java implementation of NSSet that implements Set for greater java + * interoperability. + * + * @author michael@mpowers.net + * @author $Author: cgruber $ + * @version $Revision: 893 $ + */ +public class NSSet extends HashSet { + /** + * Default constructor. + */ + public NSSet() { + super(); + } + + /** + * Constructs a NSSet containing the objects in the specified collection. + */ + public NSSet(Collection aCollection) { + super(aCollection); + } + + /** + * Constructs a NSSet containing only the specified object. + */ + public NSSet(Object anObject) { + super(); + add(anObject); + } + + /** + * Constructs a NSSet containing the objects in the specified array. + */ + public NSSet(Object[] anObjectArray) { + super(); + for (int i = 0; i < anObjectArray.length; i++) { + add(anObjectArray[i]); + } + } + + /** + * Returns an NSArray containing all objects in the set. + */ + public NSArray allObjects() { + return new NSArray(this); + } + + /** + * + */ + public Object anyObject() { + throw new RuntimeException("Not implemented yet."); + } + + /** + * Returns whether this set contains the specified object. + */ + public boolean containsObject(Object anObject) { + return contains(anObject); + } + + /** + * Returns the number of elements in this set. + */ + public int count() { + return size(); + } + + /** + * Returns whether this set has one or more elements in common with the + * specified set. + */ + public boolean intersectsSet(Set aSet) { + Iterator it = aSet.iterator(); + while (it.hasNext()) { + if (this.containsObject(it.next())) { + return true; + } + } + return false; + + } + + /** + * Returns whether this set contains the same object as the specified set. + */ + public boolean isEqualToSet(Set aSet) { + return equals(aSet); + } + + /** + * Returns whether this set is a subset of the specified set. + */ + public boolean isSubsetOfSet(Set aSet) { + return aSet.containsAll(this); + } + + /** + * + */ + public Object member(Object anObject) { + throw new RuntimeException("Not implemented yet."); + } + + /** + * Returns an enumerator over the objects in this set. + */ + public Enumeration objectEnumerator() { + return new Vector(this).elements(); + } + + /** + * Returns a set that is the intersection of this set and the specified set. + */ + public NSSet setByIntersectingSet(Set aSet) { + NSSet result = new NSSet(this); + result.retainAll(aSet); + return result; + } + + /** + * Returns a set that contains all elements in this set that are not in the + * specified set. + */ + public NSSet setBySubtractingSet(Set aSet) { + NSSet result = new NSSet(this); + result.removeAll(aSet); + return result; + } + + /** + * Returns a set that is the union of this set and the specified set. + */ + public NSSet setByUnioningSet(Set aSet) { + NSSet result = new NSSet(this); + result.addAll(aSet); + return result; + } + } /* - * $Log$ - * Revision 1.2 2006/02/16 13:15:00 cgruber - * Check in all sources in eclipse-friendly maven-enabled packages. + * $Log$ Revision 1.2 2006/02/16 13:15:00 cgruber Check in all sources in + * eclipse-friendly maven-enabled packages. * - * Revision 1.1.1.1 2000/12/21 15:47:45 mpowers - * Contributing wotonomy. + * Revision 1.1.1.1 2000/12/21 15:47:45 mpowers Contributing wotonomy. * - * Revision 1.3 2000/12/20 16:25:39 michael - * Added log to all files. + * Revision 1.3 2000/12/20 16:25:39 michael Added log to all files. * * */ - |
