|
WebObjects 5.4.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.webobjects.foundation.NSSet
public class NSSet
NSSet declares an API for an object that manages a collection of objects similar to a mathematical set. A set, both in its mathematical sense and in the implementation of NSSet, is an unordered collection of distinct elements. The NSMutableSet subclass is provided for sets whose contents may be altered.
Use sets as an alternative to arrays when the order of elements is not important and performance in testing whether an object is contained in the set is a consideration. While arrays are ordered, testing for membership is much slower than with sets.
Methods that add entries to sets, whether during construction (for all sets) or modification (for mutable sets), add each member to the set directly. This means that you must ensure that the members do not change. If the members are expected to change for any reason, you should make
copies of them and add the copies to the set or otherwise guarantee that the members do not change with respect to either the equals or hashCode methods.
The following table describes the NSSet methods that provide the basis for all NSSet's other methods; that is, all other methods are implemented in terms of these three. If you create a subclass of NSSet, you need only ensure that these base methods work properly. Having done so, you can be sure that all his subclass's inherited methods operate properly.
| Method | Description |
count |
returns the number of members in the set |
member |
returns the object in the set that is equal to the specified object |
objectsNoCopy |
returns the actual array of objects in the set |
NSSet provides methods for querying the elements of the set. The allObjects method returns an array containing the objects in a set. The anyObject method returns some object in the set. Additionally, intersectsSet tests for set intersection,
isEqualToSet tests for set equality, and isSubsetOfSet tests for one set being a subset of another.
The objectEnumerator method provides for traversing elements of the set one by one.
Set,
HashSet,
NSSet._count,
NSSet.allObjects(),
NSSet.member(java.lang.Object),
NSSet.intersectsSet(com.webobjects.foundation.NSSet),
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.webobjects.foundation.NSCoding |
|---|
NSCoding.Support |
| Field Summary | |
|---|---|
static boolean |
CheckForNull
Convenience for the constructor methods |
static NSSet |
EmptySet
A shared NSSet instance containing no members. |
static boolean |
IgnoreNull
Convenience for the constructor methods |
| Constructor Summary | |
|---|---|
NSSet()
Creates an empty NSSet. |
|
NSSet(Collection collection)
Creates an NSSet containing all the elements in collection |
|
NSSet(Object object)
Creates an NSSet containing the single object. |
|
NSSet(Object[] objects)
Creates an NSSet containing all the elements in objects Note: NSSet assumes that the member objects are immutable. |
|
NSSet(NSArray objects)
Creates an NSSet containing all the elements in objects Note: NSSet assumes that the member objects are immutable. |
|
NSSet(NSSet otherSet)
Creates a new NSSet containing the same objects as another NSSet. |
|
NSSet(Set set,
boolean ignoreNull)
Creates an NSSet containing all the elements in set |
|
| Method Summary | |
|---|---|
boolean |
add(Object o)
Operation not supported |
boolean |
addAll(Collection c)
Operation not supported |
NSArray |
allObjects()
Provides an array with all the members of this NSSet. |
Object |
anyObject()
Returns one of the objects in this set, essentially chosen at random, or null if the set contains no objects. |
Class |
classForCoder()
Conformance with NSCoding. |
void |
clear()
Operation not supported |
Object |
clone()
Since NSSets are immutable, there's no need to make an actual copy. |
boolean |
contains(Object o)
NSSets cannot contain null values and therefore do not adhere to the java.util.Set specification |
boolean |
containsAll(Collection c)
|
boolean |
containsObject(Object object)
Indicates whether a object is a member of this NSSet as determined by equals |
int |
count()
|
static Object |
decodeObject(NSCoder coder)
Creates an NSSet from the data in an NSCoder. |
static NSSet |
emptySet()
Returns the empty NSSet (immutable). |
void |
encodeWithCoder(NSCoder coder)
Encodes the receiver using coder. |
boolean |
equals(Object object)
Determines whether this NSSet is equal to object This is true if object is an NSSet or subclass of NSSet and both sets contain identical members. |
int |
hashCode()
Provides an appropriate hash code useful for storing this NSSet in a hash-based data structure. |
HashSet |
hashSet()
Creates a java.util.HashSet with the same contents as this object. |
NSSet |
immutableClone()
Since the NSSets are immutable, there's no need to make an actual |
boolean |
intersectsSet(NSSet otherSet)
The result of this method corresponds to the mathematical concept of disjoint sets: if the sets are not disjoint, this method returns true; otherwise, it returns false. |
boolean |
isEmpty()
|
boolean |
isEqualToSet(NSSet otherSet)
Provided for backward compatibility. |
boolean |
isSubsetOfSet(NSSet otherSet)
Determines whether every member of this NSSet is a member of otherSet. |
Iterator |
iterator()
|
Object |
member(Object object)
Determines whether an object is a member of this NSSet based on the results of the object's equals method. |
NSMutableSet |
mutableClone()
This method creates a duplicate NSMutableSet with the same objects. |
Enumeration |
objectEnumerator()
Provides an Enumeration object that can be used to access each member of this NSSet. |
protected Object[] |
objectsNoCopy()
This method should be used only by subclasses. |
boolean |
remove(Object o)
Operation not supported |
boolean |
removeAll(Collection c)
Operation not supported |
boolean |
retainAll(Collection c)
Operation not supported |
NSSet |
setByIntersectingSet(NSSet otherSet)
Creates a new NSSet that is the result of intersecting another NSSet with this NSSet. |
NSSet |
setBySubtractingSet(NSSet otherSet)
Creates a new NSSet whose members are in this NSSet but not in otherSet. |
NSSet |
setByUnioningSet(NSSet otherSet)
Creates a new NSSet whose members are in this NSSet or in otherSet, or both. |
int |
size()
|
Object[] |
toArray()
|
Object[] |
toArray(Object[] objects)
|
String |
toString()
The string has the form "(object1, object2, ...)". |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final NSSet EmptySet
public static final boolean CheckForNull
public static final boolean IgnoreNull
| Constructor Detail |
|---|
public NSSet()
EmptySet constant.
NSSet.EmptySetpublic NSSet(Object object)
object - single object contained in the new NSSetpublic NSSet(Object[] objects)
objects Note: NSSet assumes that the member objects are immutable. If your member objects are mutable, you should make copies of them and add the copies to the set.
objects - array of objects to be contained in the new NSSetpublic NSSet(NSArray objects)
objects Note: NSSet assumes that the member objects are immutable. If your member objects are mutable, you should make copies of them and add the copies to the set.
objects - array of objects to be contained in the new NSSetpublic NSSet(NSSet otherSet)
immutableClone instead. Note: NSSet assumes that the member objects are immutable. If your member objects are mutable, you should make copies of them and add the copies to the set.
otherSet - the set to duplicateNSSet.immutableClone(),
NSSet.mutableClone(),
NSSet.clone()
public NSSet(Set set,
boolean ignoreNull)
set
set - object that implements java.util.SetignoreNull - whether to ignore null values in vector or throw exception
IllegalArgumentException - if a null element exists in Set or the Set parameter is null.Setpublic NSSet(Collection collection)
collection
collection - object that implements java.util.Collection
IllegalArgumentException - if a null element exists in collection or java.lang.NullPointerException if the collection parameter is null.Set| Method Detail |
|---|
protected Object[] objectsNoCopy()
public int count()
public Object member(Object object)
equals method.
object - object to search for in this NSSet
object from this NSSet, or null if object is not a member.Object.equals(java.lang.Object)public NSSet setByIntersectingSet(NSSet otherSet)
otherSet.
otherSet - NSSet to intersect this NSSet with
otherSet have in commonNSSet.intersectsSet(com.webobjects.foundation.NSSet),
NSSet.isSubsetOfSet(com.webobjects.foundation.NSSet),
NSSet.setBySubtractingSet(com.webobjects.foundation.NSSet),
NSSet.setByUnioningSet(com.webobjects.foundation.NSSet)public NSSet setBySubtractingSet(NSSet otherSet)
otherSet.
otherSet - NSSet whose members are subtracted from this NSSet
otherSetNSSet.intersectsSet(com.webobjects.foundation.NSSet),
NSSet.isSubsetOfSet(com.webobjects.foundation.NSSet),
NSSet.setByIntersectingSet(com.webobjects.foundation.NSSet),
NSSet.setByUnioningSet(com.webobjects.foundation.NSSet)public NSSet setByUnioningSet(NSSet otherSet)
otherSet, or both.
otherSet - NSSet whose members are added to this NSSet
otherSetNSSet.intersectsSet(com.webobjects.foundation.NSSet),
NSSet.isSubsetOfSet(com.webobjects.foundation.NSSet),
NSSet.setByIntersectingSet(com.webobjects.foundation.NSSet),
NSSet.setBySubtractingSet(com.webobjects.foundation.NSSet)public boolean containsObject(Object object)
object is a member of this NSSet as determined by equals
object - object to search for in this NSSet
true if object is a member of this NSSetNSSet.member(java.lang.Object)public boolean intersectsSet(NSSet otherSet)
true; otherwise, it returns false.
otherSet - NSSet this NSSet is compared against
true if at least one object in this NSSet is also a member of otherSetNSSet.isSubsetOfSet(com.webobjects.foundation.NSSet)public boolean isSubsetOfSet(NSSet otherSet)
otherSet.
otherSet - the potential superset
true if this NSSet is a subset of otherSetNSSet.intersectsSet(com.webobjects.foundation.NSSet)public boolean isEqualToSet(NSSet otherSet)
equals instead.
otherSet - NSSet this NSSet is compared against
true if the contents of otherSet are equal to the contents of this NSSetNSSet.equals(java.lang.Object)public boolean equals(Object object)
object This is true if object is an NSSet or subclass of NSSet and both sets contain identical members. Two sets have equal contents if they each have the same number of members and if each member matches a
member in the other set as determined by equals.
equals in interface Collectionequals in interface Setequals in class Objectobject - the object this NSSet is compared against
true if object is an NSSet equal to this NSSetObject.equals(java.lang.Object),
NSSet.intersectsSet(com.webobjects.foundation.NSSet),
NSSet.isSubsetOfSet(com.webobjects.foundation.NSSet)public Object anyObject()
null if the set contains no objects.
null if this NSSet is emptyNSSet.allObjects(),
NSSet.objectEnumerator()public NSArray allObjects()
NSSet.anyObject(),
NSSet.objectEnumerator()public Enumeration objectEnumerator()
allObjects method to create a snapshot
of this set's members. Enumerate over the snapshot, but make your modifications to the original set.
NSSet.allObjects(),
Enumerationpublic Class classForCoder()
classForCoder in interface NSCodingNSCodingpublic static Object decodeObject(NSCoder coder)
coder - NSCoder from which the new NSSet's members are derived from
NSCodingpublic void encodeWithCoder(NSCoder coder)
NSCodingcoder. Object type information along with an object's data is stored.
encodeWithCoder in interface NSCodingcoder - an NSCoder object that will be used to encode object of classes that implement this interfaceNSCoderpublic int hashCode()
hashCode in interface CollectionhashCode in interface SethashCode in class ObjectObject.hashCode()public HashSet hashSet()
public Object clone()
clone in class ObjectthisObject.clone(),
NSSet.immutableClone(),
NSSet.mutableClone()public NSSet immutableClone()
NSSet.mutableClone(),
Object.clone()public NSMutableSet mutableClone()
NSSet.immutableClone(),
Object.clone()public String toString()
toString in class Objectpublic static final NSSet emptySet()
This example illustrates the type-safe way to obtain an empty list:
Set<String> s = NSSet.emptySet();Implementation note: Implementations of this method need not create a separate NSSet object for each call. Using this method is likely to have comparable cost to using the like-named field. (Unlike this method, the field does not provide type safety.)
NSSet.EmptySetpublic int size()
size in interface Collectionsize in interface SetSet.size()public boolean isEmpty()
isEmpty in interface CollectionisEmpty in interface SetSet.isEmpty()public boolean contains(Object o)
contains in interface Collectioncontains in interface SetSet.contains(java.lang.Object)public boolean containsAll(Collection c)
containsAll in interface CollectioncontainsAll in interface Setc - -
collection to be checked for containment in this set
NullPointerException - if c is nullSet.containsAll(java.util.Collection)public Iterator iterator()
iterator in interface Iterableiterator in interface Collectioniterator in interface SetSet.iterator()public Object[] toArray()
toArray in interface CollectiontoArray in interface SetSet.toArray()public Object[] toArray(Object[] objects)
toArray in interface CollectiontoArray in interface SetNullPointerException - for a == nullSet.toArray()public boolean add(Object o)
add in interface Collectionadd in interface SetUnsupportedOperationExceptionSet.add(E)public boolean remove(Object o)
remove in interface Collectionremove in interface SetUnsupportedOperationExceptionSet.remove(java.lang.Object)public boolean addAll(Collection c)
addAll in interface CollectionaddAll in interface SetUnsupportedOperationExceptionSet.addAll(java.util.Collection)public boolean retainAll(Collection c)
retainAll in interface CollectionretainAll in interface SetUnsupportedOperationExceptionSet.retainAll(java.util.Collection)public boolean removeAll(Collection c)
removeAll in interface CollectionremoveAll in interface SetUnsupportedOperationExceptionSet.removeAll(java.util.Collection)public void clear()
clear in interface Collectionclear in interface SetUnsupportedOperationExceptionSet.clear()
|
Last updated June 2008 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||