|
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.NSArray com.webobjects.foundation.NSMutableArray
The NSMutableArray class provides facilities for managing a mutable collection of objects. It adds insertion and deletion operations to the basic array-handling behavior inherited from its superclass, NSArray.
The following table describes the NSMutableArray methods that provide the basis for all NSMutableArray's other methods; that is, all other methods are implemented in terms of these. If you create a subclass of NSMutableArray, you need to ensure that only these base methods work properly. Having done so, you can be sure that all your subclass's inherited methods operate properly.
Method | Description |
addObject |
Adds an object to the array. |
addObjects |
Adds multiple objects to the array. |
insertObjectAtIndex |
Inserts an object into the array at a specified index. |
removeAllObjects |
Empties the receiver of all its elements. |
removeObjectAtIndex |
Removes the object at a specified index from the array. |
replaceObjectAtIndex(Object, int) |
Replaces the object at a specified index with another object. |
setArray |
Sets an array's elements to the ones in another array. |
sortUsingComparator |
Sorts the elements of the array. |
The other methods provide convenient ways of inserting an object into a specific slot in the array and removing an object based on its identity or position in the array.
List
,
ArrayList
,
Vector
,
addObject(java.lang.Object)
,
addObjects(java.lang.Object[])
,
insertObjectAtIndex(java.lang.Object, int)
,
removeAllObjects()
,
removeObjectAtIndex(int)
,
replaceObjectAtIndex(Object, int)
,
setArray(com.webobjects.foundation.NSArray)
,
sortUsingComparator(com.webobjects.foundation.NSComparator)
,
Serialized FormNested Class Summary |
Nested classes inherited from class com.webobjects.foundation.NSArray |
NSArray.Operator |
Nested classes inherited from class com.webobjects.foundation.NSCoding |
NSCoding.Support |
Nested classes inherited from class com.webobjects.foundation.NSKeyValueCoding |
NSKeyValueCoding.DefaultImplementation, NSKeyValueCoding.ErrorHandling, NSKeyValueCoding.Null, NSKeyValueCoding.UnknownKeyException, NSKeyValueCoding.Utility, NSKeyValueCoding.ValueAccessor |
Nested classes inherited from class com.webobjects.foundation.NSKeyValueCodingAdditions |
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility |
Field Summary |
Fields inherited from class com.webobjects.foundation.NSArray |
AverageOperatorName, CountOperatorName, EmptyArray, MaximumOperatorName, MinimumOperatorName, NotFound, SumOperatorName |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding |
NullValue |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
KeyPathSeparator |
Constructor Summary | |
NSMutableArray()
Creates an empty mutable array. |
|
NSMutableArray(int capacity)
Creates an empty mutable array with enough allocated memory to hold the number of objects specified by capacity , a number
greater than or equal to 0. |
|
NSMutableArray(NSArray otherArray)
One should use the mutableClone method instead. |
|
NSMutableArray(Object object)
Creates a mutable array containing the single element object . |
|
NSMutableArray(Object[] objects)
Creates a mutable array containing objects . |
|
NSMutableArray(Object[] objects,
NSRange range)
Creates a mutable array containing the objects from objects in
the range specified by range . |
|
NSMutableArray(Vector vector,
NSRange range,
boolean ignoreNull)
Creates a mutable array containing the objects from vector in
the range specified by range . |
Method Summary | |
void |
addObject(Object object)
Inserts object at the end of this array. |
void |
addObjects(Object[] objects)
Adds all the elements of objects to the end of this
array. |
void |
addObjectsFromArray(NSArray otherArray)
Adds the objects from otherArray to the end of the
this array. |
Object |
clone()
Creates a clone of this array. |
NSArray |
immutableClone()
Creates a new NSArray with the same elements as this array. |
void |
insertObjectAtIndex(Object object,
int index)
Inserts object into this array at index . |
NSMutableArray |
mutableClone()
Creates a new NSMutableArray with the same elements as this array. |
void |
removeAllObjects()
Deletes all of the elements from this array. |
boolean |
removeIdenticalObject(Object object)
Removes all occurrences of object throughout the array. |
boolean |
removeIdenticalObject(Object object,
NSRange range)
As removeIdenticalObject(Object object) but it only searchs a subset of
this array as specified by range . |
Object |
removeLastObject()
Removes this array's last element (the highest-valued index). |
boolean |
removeObject(Object object)
Removes all occurrences of object throughout this array. |
boolean |
removeObject(Object object,
NSRange range)
Same as removeObject(Object object) but only searches a subset of this array as
specified by NSRange . |
Object |
removeObjectAtIndex(int index)
Removes the object at index and moves all elements beyond
index up one slot to fill the gap. |
void |
removeObjects(Object[] objects)
This method is similar to removeObject , but allows you to efficiently
remove all the objects in objects with a single operation. |
void |
removeObjectsInArray(NSArray otherArray)
This method is similar to removeObject , but allows you to efficiently
remove the set of objects in otherArray with a single
operation. |
void |
removeObjectsInRange(NSRange range)
Removes each of the objects within the specified range from this array using removeObjectAtIndex . |
void |
replaceObjectAtIndex(int index,
Object object)
Deprecated. This method was provided for backward compatibility only. |
Object |
replaceObjectAtIndex(Object object,
int index)
Replaces the object at index with object . |
void |
replaceObjectsInRange(NSRange range,
NSArray otherArray,
NSRange otherRange)
Replaces a subset of the objects in this array as specified by range with
a subset of the objects in otherArray as specified by otherRange . |
void |
setArray(NSArray otherArray)
Sets this array's elements to those in otherArray . |
void |
sortUsingComparator(NSComparator comparator)
Sorts this array's elements, as determined by comparator . |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public NSMutableArray()
public NSMutableArray(int capacity)
capacity
, a number
greater than or equal to 0.
NSMutableArrays expand as needed, so capacity
simply establishes
the object's initial capacity.
capacity
- a size hint for the anticipated upper boundpublic NSMutableArray(Object object)
object
.
object
- the single element contained in the mutable arraypublic NSMutableArray(Object[] objects)
objects
.
objects
- the objects contained in the mutable arraypublic NSMutableArray(Object[] objects, NSRange range)
objects
in
the range specified by range
.After an immutable array has been initialized in this way, it can't be modified.
objects
- the objects contained in the mutable arrayrange
- the range specifiedpublic NSMutableArray(NSArray otherArray)
mutableClone
method instead.
Creates a mutable array containing the objects in otherArray
.
otherArray
- contains the objectsmutableClone()
public NSMutableArray(Vector vector, NSRange range, boolean ignoreNull)
vector
in
the range specified by range
.
The ignoreNull
argument controls the method's behavior when it
encounters a null
value in the vector: if ignoreNull
is true
, the null
value is simply ignored.
vector
- mutable array contains objects from thisrange
- the specified rangeignoreNull
- the null
value is ignored
IllegalArgumentException
- if ignoreNull
is false
and a null
reference exists within
the specified range of the vector.Vector
Method Detail |
public void addObject(Object object)
object
at the end of this array.
object
- the object to be inserted
IllegalArgumentException
- if object is null
public void addObjects(Object[] objects)
objects
to the end of this
array.
objects
- the array of objects to append
IllegalArgumentException
- if any of the objects
in objects
are null
public void addObjectsFromArray(NSArray otherArray)
otherArray
to the end of the
this array.
otherArray
- the objects to be appended to this arraypublic Object clone()
clone
in class NSArray
immutableClone()
,
mutableClone()
,
Object.clone()
public NSArray immutableClone()
immutableClone
in class NSArray
mutableClone()
,
clone()
public void insertObjectAtIndex(Object object, int index)
object
into this array at index
.
If index
is already occupied, the objects at index
and
beyond are shifted down one slot to make room. index
cannot
be greater than the number of elements in the array. Note that NSArrays are not like C arrays. That is, even though you might specify a size when you create an array, the specified size is regarded as a hint; the actual size of the array is still 0. Because of this, you can only insert new objects in ascending order without gaps. Once you add two objects, the array's size is 2, so you can add objects at indexes 0, 1, or 2. Index 3 is illegal and out of bounds; if you try to add an object at index 3 (when the size of the array is 2), NSMutableArray throws an exception.
object
- the object to be insertedindex
- the position in this array to place the new object
IllegalArgumentException
- if object
is null
or if index
is greater than the number of elements in the arraypublic NSMutableArray mutableClone()
mutableClone
in class NSArray
immutableClone()
,
clone()
public void removeAllObjects()
public boolean removeIdenticalObject(Object object)
object
throughout the array.
Unlike removeObject(Object object)
this method uses == to determine
equivalence instead of equals
.
object
- its occurence is removed throughout the array
true
if one or more objects were actually removed
IllegalArgumentException
- if object is null
removeObject(java.lang.Object)
public boolean removeIdenticalObject(Object object, NSRange range)
removeIdenticalObject(Object object)
but it only searchs a subset of
this array as specified by range
.
object
- all occurrences of this within the subrange are removed from this arrayrange
- the specified range
true
if one or more objects were actually removed
IllegalArgumentException
- if object is null
or if range
is out of boundsremoveIdenticalObject(java.lang.Object)
public Object removeLastObject()
null
if the array is empty.
null
public boolean removeObject(Object object)
object
throughout this array.
Elements in this array are considered equivalent to object
if equals
returns true
.
object
- the object for which all equivalent objects will be deleted from this array
true
if one or more objects were actually removed
IllegalArgumentException
- if object
is
null
removeObjectAtIndex(int)
,
NSArray.indexOfObject(java.lang.Object)
public boolean removeObject(Object object, NSRange range)
removeObject(Object object)
but only searches a subset of this array as
specified by NSRange
.
object
- occurrences of this are removed throughout the subrange of this arrayrange
- the specified subset to search
true
if one or more objects were actually removed
IllegalArgumentException
- if anObject is null
or
if range
is out of boundsremoveObject(java.lang.Object)
public Object removeObjectAtIndex(int index)
index
and moves all elements beyond
index
up one slot to fill the gap.
index
- the object at this position is removed
null
IllegalArgumentException
- if the array is empty
or if index
is beyond the end of the arraypublic void removeObjects(Object[] objects)
removeObject
, but allows you to efficiently
remove all the objects in objects
with a single operation.
objects
- the set of objects to be removedremoveObject(java.lang.Object)
public void removeObjectsInArray(NSArray otherArray)
removeObject
, but allows you to efficiently
remove the set of objects in otherArray
with a single
operation.
otherArray
- the set of objects in this are removedremoveObject(java.lang.Object)
public void removeObjectsInRange(NSRange range)
removeObjectAtIndex
.
range
- the range specified
IllegalArgumentException
- if range
is out of boundsremoveObjectAtIndex(int)
public Object replaceObjectAtIndex(Object object, int index)
index
with object
.
object
- the new object to be placed at this indexindex
- the index into the array for the new object
index
which was replaced, or null
IllegalArgumentException
- if object
is
null
or if index
is beyond
the end of the arraypublic void replaceObjectAtIndex(int index, Object object)
replaceObjectAtIndex(Object, int)
instead.
index
- position to place the new objectobject
- the new object to occupy the position at indexreplaceObjectAtIndex(Object, int)
public void replaceObjectsInRange(NSRange range, NSArray otherArray, NSRange otherRange)
range
with
a subset of the objects in otherArray
as specified by otherRange
.
range
and otherRange
do not have to be equal; if
range
is greater than otherRange
, the extra objects
in this array are removed. If otherRange
is greater than
range
, the extra objects from otherArray
are inserted into this array.
range
- subset of objects in this array to replaceotherArray
- the array of new objectsotherRange
- range subset of objects in otherArray
to usepublic void setArray(NSArray otherArray)
otherArray
.
Any existing elements are replaced.
It truncates this array, if necessary, so that it contains no more
than the number of elements in otherArray
. If
there are more elements in otherArray
than there are in this
array, the additional items are added.
otherArray
- the elements to replace those in this arraypublic void sortUsingComparator(NSComparator comparator) throws NSComparator.ComparisonException
comparator
.
comparator
- determines sorting behavior
NSComparator.ComparisonException
- if comparator
cannot sort these elements
IllegalArgumentException
- if comparator
is null
NSArray.sortedArrayUsingComparator(com.webobjects.foundation.NSComparator)
,
NSComparator
|
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 |