From aedc34d55462a75e329bbf342251ff6504cd117e Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Sun, 19 May 2024 17:56:33 -0400 Subject: Initial import from SVN --- .../main/java/net/wotonomy/foundation/NSSet.java | 212 +++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSet.java (limited to 'projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSet.java') 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 new file mode 100644 index 0000000..5318fe8 --- /dev/null +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSet.java @@ -0,0 +1,212 @@ +/* +Wotonomy: OpenStep design patterns for pure Java applications. +Copyright (C) 2000 Blacksmith, Inc. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, see http://www.gnu.org +*/ + +package net.wotonomy.foundation; + +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Iterator; +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; + } + +} + +/* + * $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.3 2000/12/20 16:25:39 michael + * Added log to all files. + * + * + */ + -- cgit v1.2.3