WebObjects 5.4

com.webobjects.foundation
Class NSMutableSet<E>

java.lang.Object
  extended by com.webobjects.foundation.NSSet<E>
      extended by com.webobjects.foundation.NSMutableSet<E>
All Implemented Interfaces:
NSCoding, Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>

public class NSMutableSet<E>
extends NSSet<E>

NSMutableSet provides support for the mathematical concept of a set which, unlike its parent NSSet, may have members added or removed after its creation.

The following table describes the NSMutableSet methods that provide the basis for all NSMutableSet's other methods; that is, all other methods are implemented in terms of these five. If you create a subclass of NSMutableSet, you need only ensure that these base methods work properly. Having done so, you can be sure that all your subclass's inherited methods operate properly.

NSMutableSet's Base API
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.
removeAllObjects Empties the set of all its members.
removeObject Removes the specified object from the set.

Objects are removed from an NSMutableSet using any of the methods intersectSet, removeAllObjects, removeObject or subtractSet.

Objects are added to an NSMutableSet with addObject, which adds a single object to the set; addObjectsFromArray, which adds all objects from a specified array to the set; or with unionSet, which adds all the objects from another set.

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 guarentee that the members do not change with respect to either the equals or hashCode methods.

See Also:
Set, HashSet, addObject(java.lang.Object), removeObject(java.lang.Object), removeAllObjects(), unionSet(com.webobjects.foundation.NSSet), intersectSet(com.webobjects.foundation.NSSet), subtractSet(com.webobjects.foundation.NSSet), addObjectsFromArray(com.webobjects.foundation.NSArray), Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSCoding
NSCoding.Support
 
Field Summary
 
Fields inherited from class com.webobjects.foundation.NSSet
CheckForNull, EmptySet, IgnoreNull
 
Constructor Summary
NSMutableSet()
          Creates an empty NSMutableSet.
NSMutableSet(Collection<? extends E> collection)
          Creates an NSMutableSet containing all the elements in collection
NSMutableSet(E object)
          Creates an NSMutableSet containing a single object object.
NSMutableSet(E[] objects)
          Creates an NSMutableSet containing the all the elements in objects.
NSMutableSet(int capacity)
          Creates an empty NSMutableSet prepared to hold at least capacity members.
NSMutableSet(NSArray<? extends E> objects)
          Creates an NSMutableSet containing the all the elements in objects.
NSMutableSet(NSSet<? extends E> otherSet)
          Creates an NSMutableSet containing all the members in otherSet.
 
Method Summary
 boolean add(E element)
          Operation not supported
 boolean addAll(Collection<? extends E> collection)
          Operation not supported
 void addObject(Object object)
          Adds the specified object to this set if it is not already a member.
 void addObjectsFromArray(NSArray array)
          Adds each object contained in array to this set, if the object is not already a member.
 void clear()
          Operation not supported
 Object clone()
          Creates a clone of the receiver.
 NSSet<E> immutableClone()
          Creates a new NSSet which has the same members as this set.
 void intersectSet(NSSet<?> otherSet)
          Removes from this set each object that is not a member of otherSet.
 NSMutableSet<E> mutableClone()
          Creates a new NSMutableSet which has the same members as this set.
 boolean remove(Object element)
          Operation not supported
 boolean removeAll(Collection<?> collection)
          Operation not supported
 void removeAllObjects()
          Empties the set of all its members.
 E removeObject(Object object)
          Removes object from the set.
 boolean retainAll(Collection collection)
          Operation not supported
 void setSet(NSSet<? extends E> otherSet)
          Makes this set contain exactly the same members as otherSet The current members in this set are discarded.
 void subtractSet(NSSet<?> otherSet)
          Removes from this set each object contained in otherSet that is also currently a member of this set.
 void unionSet(NSSet<?> otherSet)
          Adds each object contained in otherSet to this set, if that object is not already a member.
 
Methods inherited from class com.webobjects.foundation.NSSet
allObjects, anyObject, classForCoder, contains, containsAll, containsObject, count, decodeObject, emptySet, encodeWithCoder, equals, hashCode, hashSet, intersectsSet, isEmpty, isEqualToSet, isSubsetOfSet, iterator, member, objectEnumerator, objectsNoCopy, setByIntersectingSet, setBySubtractingSet, setByUnioningSet, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NSMutableSet

public NSMutableSet()
Creates an empty NSMutableSet.

For better performance, one should use NSMutableSet(int capacity) instead.

See Also:
NSMutableSet(int capacity)

NSMutableSet

public NSMutableSet(int capacity)
Creates an empty NSMutableSet prepared to hold at least capacity members. NSMutableSets grow as necessary, so this is a recommended performance enhancement.

Parameters:
capacity - a size hint for the expected number of members

NSMutableSet

public NSMutableSet(E object)
Creates an NSMutableSet containing a single object object.

Note: NSMutableSet assumes that member objects are immutable. If your member objects are mutable, you should make copies of them and add the copies to the set.

Parameters:
object - the single member object contained in the set

NSMutableSet

public NSMutableSet(E[] objects)
Creates an NSMutableSet containing the all the elements in objects.

Note: NSMutableSet assumes that member objects are immutable. If your member objects are mutable, you should make copies of them and add the copies to the set.

Parameters:
objects - an array of initial members for the new set

NSMutableSet

public NSMutableSet(NSArray<? extends E> objects)
Creates an NSMutableSet containing the all the elements in objects.

Note: NSMutableSet assumes that member objects are immutable. If your member objects are mutable, you should make copies of them and add the copies to the set.

Parameters:
objects - an array of initial members for the new set

NSMutableSet

public NSMutableSet(NSSet<? extends E> otherSet)
Creates an NSMutableSet containing all the members in otherSet. One should use mutableClone instead.

Parameters:
otherSet - the set to duplicate
See Also:
mutableClone()

NSMutableSet

public NSMutableSet(Collection<? extends E> collection)
Creates an NSMutableSet containing all the elements in collection

Parameters:
collection - object that implements java.util.Collection
Throws:
IllegalArgumentException - if a null element exists in collection or the collection parameter is null.
Since:
5.4
See Also:
Set
Method Detail

addObject

public void addObject(Object object)
Adds the specified object to this set if it is not already a member.

If object is already present in the set, this method has no effect on either the set or on object.

Note: NSMutableSet assumes that member objects are immutable. If your member objects are mutable, you should make copies of them and add the copies to the set.

Parameters:
object - the new member
See Also:
addObjectsFromArray(com.webobjects.foundation.NSArray), unionSet(com.webobjects.foundation.NSSet)

removeObject

public E removeObject(Object object)
Removes object from the set.

Parameters:
object - object that is to be removed from the set
Returns:
the equivalent object removed from this set, or null if object was not a member
See Also:
removeAllObjects(), intersectSet(com.webobjects.foundation.NSSet), subtractSet(com.webobjects.foundation.NSSet)

removeAllObjects

public void removeAllObjects()
Empties the set of all its members.

See Also:
removeObject(java.lang.Object), intersectSet(com.webobjects.foundation.NSSet), subtractSet(com.webobjects.foundation.NSSet)

setSet

public void setSet(NSSet<? extends E> otherSet)
Makes this set contain exactly the same members as otherSet The current members in this set are discarded.

Parameters:
otherSet - the new members for this set

addObjectsFromArray

public void addObjectsFromArray(NSArray array)
Adds each object contained in array to this set, if the object is not already a member. If a given element of the array is already present in the set, this method has no effect on either the set or on the array element.

Note: NSMutableSet assumes that member objects are immutable. If your member objects are mutable, you should make copies of them and add the copies to the set.

Parameters:
array - objects are contained in this
See Also:
addObject(java.lang.Object), unionSet(com.webobjects.foundation.NSSet)

intersectSet

public void intersectSet(NSSet<?> otherSet)
Removes from this set each object that is not a member of otherSet.

Parameters:
otherSet - objects that are not members of otherSet are removed
See Also:
removeObject(java.lang.Object), removeAllObjects(), subtractSet(com.webobjects.foundation.NSSet)

subtractSet

public void subtractSet(NSSet<?> otherSet)
Removes from this set each object contained in otherSet that is also currently a member of this set. If any member of otherSet is not present in this set, this method has no effect on that member.

Parameters:
otherSet - objects contained in otherSet are removed if they are also members of this set
See Also:
removeObject(java.lang.Object), removeAllObjects(), intersectSet(com.webobjects.foundation.NSSet)

unionSet

public void unionSet(NSSet<?> otherSet)
Adds each object contained in otherSet to this set, if that object is not already a member. If any member of otherSet is already a member of this set, this method has no effect on that member.

Parameters:
otherSet - each object contained in otherSet are added to this set
See Also:
addObject(java.lang.Object), addObjectsFromArray(com.webobjects.foundation.NSArray)

clone

public Object clone()
Creates a clone of the receiver. NSMutableSet's implementation simply creates a new NSMutableSet with the same members as this set.

Overrides:
clone in class NSSet<E>
Returns:
creates a clone of this NSMutableSet
See Also:
Object.clone(), immutableClone(), mutableClone()

immutableClone

public NSSet<E> immutableClone()
Creates a new NSSet which has the same members as this set.

Overrides:
immutableClone in class NSSet<E>
Returns:
an immutable copy (an NSSet) of this set.
See Also:
Object.clone(), mutableClone()

mutableClone

public NSMutableSet<E> mutableClone()
Creates a new NSMutableSet which has the same members as this set.

Overrides:
mutableClone in class NSSet<E>
Returns:
an NSMutableSet which is a duplicate of this set
See Also:
Object.clone(), immutableClone()

remove

public boolean remove(Object element)
Description copied from class: NSSet
Operation not supported

Specified by:
remove in interface Collection<E>
Specified by:
remove in interface Set<E>
Overrides:
remove in class NSSet<E>
Parameters:
element - to be removed from this list, if present.
Since:
5.4
See Also:
Collection.remove(java.lang.Object)

clear

public void clear()
Description copied from class: NSSet
Operation not supported

Specified by:
clear in interface Collection<E>
Specified by:
clear in interface Set<E>
Overrides:
clear in class NSSet<E>
Since:
5.4
See Also:
Collection.clear(), removeAllObjects()

retainAll

public boolean retainAll(Collection collection)
Description copied from class: NSSet
Operation not supported

Specified by:
retainAll in interface Collection<E>
Specified by:
retainAll in interface Set<E>
Overrides:
retainAll in class NSSet<E>
Since:
5.4
See Also:
Collection.retainAll(java.util.Collection)

removeAll

public boolean removeAll(Collection<?> collection)
Description copied from class: NSSet
Operation not supported

Specified by:
removeAll in interface Collection<E>
Specified by:
removeAll in interface Set<E>
Overrides:
removeAll in class NSSet<E>
Since:
5.4
See Also:
Collection.removeAll(java.util.Collection)

add

public boolean add(E element)
Description copied from class: NSSet
Operation not supported

Specified by:
add in interface Collection<E>
Specified by:
add in interface Set<E>
Overrides:
add in class NSSet<E>
Parameters:
element - - object to add
Since:
5.4
See Also:
Collection.add(E)

addAll

public boolean addAll(Collection<? extends E> collection)
Description copied from class: NSSet
Operation not supported

Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface Set<E>
Overrides:
addAll in class NSSet<E>
Parameters:
collection - - collection to add
Since:
5.4
See Also:
Collection.addAll(java.util.Collection)

Last updated Tuesday, October 9, 2007 08:58 PDT

Copyright © 2000-2007 Apple Inc.