|
WebObjects 5.3 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.webobjects.foundation.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
,
count()
,
allObjects()
,
member(java.lang.Object)
,
intersectsSet(com.webobjects.foundation.NSSet)
,
Serialized FormNested Class Summary |
Nested classes inherited from class com.webobjects.foundation.NSCoding |
NSCoding.Support |
Field Summary | |
static NSSet |
EmptySet
A shared NSSet instance containing no members. |
Constructor Summary | |
NSSet()
Creates an empty NSSet. |
|
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(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(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. |
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[] a)
|
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
Constructor Detail |
public NSSet()
EmptySet
constant.
EmptySet
public 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 duplicateimmutableClone()
,
mutableClone()
,
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
.Set
Method Detail |
public boolean add(Object o)
add
in interface Set
UnsupportedOperationException
Set.add(java.lang.Object)
public boolean addAll(Collection c)
addAll
in interface Set
UnsupportedOperationException
Set.addAll(java.util.Collection)
public NSArray allObjects()
anyObject()
,
objectEnumerator()
public Object anyObject()
null
if the set contains no objects.
null
if this NSSet is emptyallObjects()
,
objectEnumerator()
public Class classForCoder()
classForCoder
in interface NSCoding
NSCoding
public void clear()
clear
in interface Set
UnsupportedOperationException
Set.clear()
public Object clone()
this
Object.clone()
,
immutableClone()
,
mutableClone()
public boolean contains(Object o)
contains
in interface Set
Set.contains(java.lang.Object)
public boolean containsAll(Collection c)
containsAll
in interface Set
c
- - collection to be checked for containment in this set
NullPointerException
- if c is nullSet.containsAll(java.util.Collection)
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 NSSetmember(java.lang.Object)
public int count()
public static Object decodeObject(NSCoder coder)
coder
- NSCoder from which the new NSSet's members are derived from
NSCoding
public void encodeWithCoder(NSCoder coder)
NSCoding
coder
. Object type information along with an
object's data is stored.
encodeWithCoder
in interface NSCoding
coder
- an NSCoder object that will be used to encode object of classes that
implement this interfaceNSCoder
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 Set
object
- the object this NSSet is compared against
true
if object
is an NSSet equal to this NSSetObject.equals(java.lang.Object)
,
intersectsSet(com.webobjects.foundation.NSSet)
,
isSubsetOfSet(com.webobjects.foundation.NSSet)
public int hashCode()
hashCode
in interface Set
Object.hashCode()
public HashSet hashSet()
public NSSet immutableClone()
mutableClone()
,
Object.clone()
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 otherSet
isSubsetOfSet(com.webobjects.foundation.NSSet)
public boolean isEmpty()
isEmpty
in interface Set
Set.isEmpty()
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 NSSetequals(java.lang.Object)
public boolean isSubsetOfSet(NSSet otherSet)
otherSet
.
otherSet
- the potential superset
true
if this NSSet is a subset of otherSet
intersectsSet(com.webobjects.foundation.NSSet)
public Iterator iterator()
iterator
in interface Set
Set.iterator()
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 NSMutableSet mutableClone()
immutableClone()
,
Object.clone()
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.
allObjects()
,
Enumeration
protected Object[] objectsNoCopy()
public boolean remove(Object o)
remove
in interface Set
UnsupportedOperationException
Set.remove(java.lang.Object)
public boolean removeAll(Collection c)
removeAll
in interface Set
UnsupportedOperationException
Set.removeAll(java.util.Collection)
public boolean retainAll(Collection c)
retainAll
in interface Set
UnsupportedOperationException
Set.retainAll(java.util.Collection)
public NSSet setByIntersectingSet(NSSet otherSet)
otherSet
.
otherSet
- NSSet to intersect this NSSet with
otherSet
have in commonintersectsSet(com.webobjects.foundation.NSSet)
,
isSubsetOfSet(com.webobjects.foundation.NSSet)
,
setBySubtractingSet(com.webobjects.foundation.NSSet)
,
setByUnioningSet(com.webobjects.foundation.NSSet)
public NSSet setBySubtractingSet(NSSet otherSet)
otherSet
.
otherSet
- NSSet whose members are subtracted from this NSSet
otherSet
intersectsSet(com.webobjects.foundation.NSSet)
,
isSubsetOfSet(com.webobjects.foundation.NSSet)
,
setByIntersectingSet(com.webobjects.foundation.NSSet)
,
setByUnioningSet(com.webobjects.foundation.NSSet)
public NSSet setByUnioningSet(NSSet otherSet)
otherSet
, or both.
otherSet
- NSSet whose members are added to this NSSet
otherSet
intersectsSet(com.webobjects.foundation.NSSet)
,
isSubsetOfSet(com.webobjects.foundation.NSSet)
,
setByIntersectingSet(com.webobjects.foundation.NSSet)
,
setBySubtractingSet(com.webobjects.foundation.NSSet)
public int size()
size
in interface Set
Set.size()
public Object[] toArray()
toArray
in interface Set
Set.toArray()
public Object[] toArray(Object[] a)
toArray
in interface Set
NullPointerException
- for a == nullSet.toArray()
public String toString()
|
Last updated Thu May 26 13:46:12 PDT 2005. | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |