|
WebObjects 5.4 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.webobjects.foundation.NSSet<E>
public class NSSet<E>
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 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<? extends E> collection)
Creates an NSSet containing all the elements in collection |
|
NSSet(E object)
Creates an NSSet containing the single object. |
|
NSSet(E[] objects)
Creates an NSSet containing all the elements in objects Note: NSSet assumes that the member objects are immutable. |
|
NSSet(NSArray<? extends E> objects)
Creates an NSSet containing all the elements in objects Note: NSSet assumes that the member objects are immutable. |
|
NSSet(NSSet<? extends E> otherSet)
Creates a new NSSet containing the same objects as another NSSet. |
|
NSSet(Set<? extends E> set,
boolean ignoreNull)
Creates an NSSet containing all the elements in set |
|
| Method Summary | ||
|---|---|---|
boolean |
add(E o)
Operation not supported |
|
boolean |
addAll(Collection<? extends E> c)
Operation not supported |
|
NSArray<E> |
allObjects()
Provides an array with all the members of this NSSet. |
|
E |
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
|
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<E> |
hashSet()
Creates a java.util.HashSet with the same contents as this object. |
|
NSSet<E> |
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<E> |
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<E> |
mutableClone()
This method creates a duplicate NSMutableSet with the same objects. |
|
Enumeration<E> |
objectEnumerator()
Provides an Enumeration object that can be used to access each member of this NSSet. |
|
protected E[] |
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<E> |
setByIntersectingSet(NSSet<?> otherSet)
Creates a new NSSet that is the result of intersecting another NSSet with this NSSet. |
|
NSSet<E> |
setBySubtractingSet(NSSet<?> otherSet)
Creates a new NSSet whose members are in this NSSet but not in otherSet. |
|
NSSet<E> |
setByUnioningSet(NSSet<?> otherSet)
Creates a new NSSet whose members are in this NSSet or in otherSet, or both. |
|
int |
size()
|
|
Object[] |
toArray()
|
|
|
toArray(T[] 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.
EmptySetpublic NSSet(E object)
object - single object contained in the new NSSetpublic NSSet(E[] 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<? extends E> 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<? extends E> 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<? extends E> 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<? extends E> 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 E[] 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<E> 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<E> setBySubtractingSet(NSSet<?> otherSet)
otherSet.
otherSet - NSSet whose members are subtracted from this NSSet
otherSetintersectsSet(com.webobjects.foundation.NSSet),
isSubsetOfSet(com.webobjects.foundation.NSSet),
setByIntersectingSet(com.webobjects.foundation.NSSet>),
setByUnioningSet(com.webobjects.foundation.NSSet>)public NSSet<E> setByUnioningSet(NSSet<?> otherSet)
otherSet, or both.
otherSet - NSSet whose members are added to this NSSet
otherSetintersectsSet(com.webobjects.foundation.NSSet),
isSubsetOfSet(com.webobjects.foundation.NSSet),
setByIntersectingSet(com.webobjects.foundation.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 NSSetmember(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 otherSetisSubsetOfSet(com.webobjects.foundation.NSSet)public boolean isSubsetOfSet(NSSet otherSet)
otherSet.
otherSet - the potential superset
true if this NSSet is a subset of otherSetintersectsSet(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 NSSetequals(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 Collection<E>equals in interface Set<E>equals in class Objectobject - 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 E anyObject()
null if the set contains no objects.
null if this NSSet is emptyallObjects(),
objectEnumerator()public NSArray<E> allObjects()
anyObject(),
objectEnumerator()public Enumeration<E> 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(),
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 Collection<E>hashCode in interface Set<E>hashCode in class ObjectObject.hashCode()public HashSet<E> hashSet()
public Object clone()
clone in class ObjectthisObject.clone(),
immutableClone(),
mutableClone()public NSSet<E> immutableClone()
mutableClone(),
Object.clone()public NSMutableSet<E> mutableClone()
immutableClone(),
Object.clone()public String toString()
toString in class Objectpublic static final <T> NSSet<T> 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.)
EmptySetpublic int size()
size in interface Collection<E>size in interface Set<E>Set.size()public boolean isEmpty()
isEmpty in interface Collection<E>isEmpty in interface Set<E>Set.isEmpty()public boolean contains(Object o)
contains in interface Collection<E>contains in interface Set<E>Set.contains(java.lang.Object)public boolean containsAll(Collection<?> c)
containsAll in interface Collection<E>containsAll in interface Set<E>c - -
collection to be checked for containment in this set
NullPointerException - if c is nullSet.containsAll(java.util.Collection>)public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in interface Set<E>Set.iterator()public Object[] toArray()
toArray in interface Collection<E>toArray in interface Set<E>Set.toArray()public <T> T[] toArray(T[] objects)
toArray in interface Collection<E>toArray in interface Set<E>NullPointerException - for a == nullSet.toArray()public boolean add(E o)
add in interface Collection<E>add in interface Set<E>UnsupportedOperationExceptionSet.add(E)public boolean remove(Object o)
remove in interface Collection<E>remove in interface Set<E>UnsupportedOperationExceptionSet.remove(java.lang.Object)public boolean addAll(Collection<? extends E> c)
addAll in interface Collection<E>addAll in interface Set<E>UnsupportedOperationExceptionSet.addAll(java.util.Collection extends E>)public boolean retainAll(Collection<?> c)
retainAll in interface Collection<E>retainAll in interface Set<E>UnsupportedOperationExceptionSet.retainAll(java.util.Collection>)public boolean removeAll(Collection<?> c)
removeAll in interface Collection<E>removeAll in interface Set<E>UnsupportedOperationExceptionSet.removeAll(java.util.Collection>)public void clear()
clear in interface Collection<E>clear in interface Set<E>UnsupportedOperationExceptionSet.clear()
|
Last updated Tuesday, October 9, 2007 08:58 PDT | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||