API 0.9.5
Foundation/CPSet/CPMutableSet.j
Go to the documentation of this file.
00001 
00009 @implementation CPMutableSet : CPSet
00010 {
00011     id __doxygen__;
00012 }
00013 
00014 /*
00015     Returns an initialized set with a given initial capacity.
00016     @param aCapacity, only present for compatability
00017 */
00018 - (id)initWithCapacity:(unsigned)aCapacity
00019 {
00020     return [self init];
00021 }
00022 
00023 /*
00024     Creates and returns a set with a given initial capacity.
00025     @param aCapacity, only present for compatability
00026 */
00027 + (id)setWithCapacity:(CPUInteger)aCapacity
00028 {
00029     return [[self alloc] initWithCapacity:aCapacity];
00030 }
00031 
00032 - (void)filterUsingPredicate:(CPPredicate)aPredicate
00033 {
00034     var object,
00035         objectEnumerator = [self objectEnumerator];
00036 
00037     while ((object = [objectEnumerator nextObject]) !== nil)
00038         if (![aPredicate evaluateWithObject:object])
00039             [self removeObject:object];
00040 }
00041 
00042 - (void)removeObject:(id)anObject
00043 {
00044     _CPRaiseInvalidAbstractInvocation(self, _cmd);
00045 }
00046 
00047 - (void)removeObjectsInArray:(CPArray)anArray
00048 {
00049     var index = 0,
00050         count = [anArray count];
00051 
00052     for (; index < count; ++index)
00053         [self removeObject:[anArray objectAtIndex:index]];
00054 }
00055 
00056 - (void)removeAllObjects
00057 {
00058     var object,
00059         objectEnumerator = [self objectEnumerator];
00060 
00061     while ((object = [objectEnumerator nextObject]) !== nil)
00062         [self removeObject:object];
00063 }
00064 
00065 /*
00066     Adds to the receiver each object contained in a given array that is not already a member.
00067     @param array An array of objects to add to the receiver.
00068 */
00069 - (void)addObjectsFromArray:(CPArray)objects
00070 {
00071     var count = [objects count];
00072 
00073     while (count--)
00074         [self addObject:objects[count]];
00075 }
00076 
00077 /*
00078     Adds to the receiver each object contained in another given set
00079     @param set The set of objects to add to the receiver.
00080 */
00081 - (void)unionSet:(CPSet)aSet
00082 {
00083     var object,
00084         objectEnumerator = [aSet objectEnumerator];
00085 
00086     while ((object = [objectEnumerator nextObject]) !== nil)
00087         [self addObject:object];
00088 }
00089 
00090 /*
00091     Removes from the receiver each object contained in another given set that is present in the receiver.
00092     @param set The set of objects to remove from the receiver.
00093 */
00094 - (void)minusSet:(CPSet)aSet
00095 {
00096     var object,
00097         objectEnumerator = [aSet objectEnumerator];
00098 
00099     while ((object = [objectEnumerator nextObject]) !== nil)
00100         [self removeObject:object];
00101 }
00102 
00103 /*
00104     Removes from the receiver each object that isn't a member of another given set.
00105     @param set The set with which to perform the intersection.
00106 */
00107 - (void)intersectSet:(CPSet)aSet
00108 {
00109     var object,
00110         objectEnumerator = [self objectEnumerator],
00111         objectsToRemove = [];
00112 
00113     while ((object = [objectEnumerator nextObject]) !== nil)
00114         if (![aSet containsObject:object])
00115             objectsToRemove.push(object);
00116 
00117     var count = [objectsToRemove count];
00118 
00119     while (count--)
00120         [self removeObject:objectsToRemove[count]];
00121 }
00122 
00123 /*
00124     Empties the receiver, then adds to the receiver each object contained in another given set.
00125     @param set The set whose members replace the receiver's content.
00126 */
00127 - (void)setSet:(CPSet)aSet
00128 {
00129     [self removeAllObjects];
00130     [self unionSet:aSet];
00131 }
00132 
00133 @end
00134 
 All Classes Files Functions Variables Defines