|
WebObjects 5.4.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.webobjects.foundation.NSArray
com.webobjects.foundation.NSMutableArray
public class 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,
NSMutableArray.addObject(java.lang.Object),
NSMutableArray.addObjects(java.lang.Object[]),
NSMutableArray.insertObjectAtIndex(E, int),
NSMutableArray.removeAllObjects(),
NSMutableArray.removeObjectAtIndex(int),
NSMutableArray.replaceObjectAtIndex(Object, int),
NSMutableArray.setArray(com.webobjects.foundation.NSArray),
NSMutableArray.sortUsingComparator(com.webobjects.foundation.NSComparator),
Serialized Form| Nested Class Summary | |
|---|---|
class |
NSMutableArray.MutableArrayListIterator
|
| Nested classes/interfaces inherited from class com.webobjects.foundation.NSArray |
|---|
NSArray.Operator |
| Nested classes/interfaces inherited from interface com.webobjects.foundation.NSCoding |
|---|
NSCoding.Support |
| Nested classes/interfaces inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
|---|
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility |
| Field Summary |
|---|
| Fields inherited from class com.webobjects.foundation.NSArray |
|---|
AverageOperatorName, CheckForNull, CountOperatorName, EmptyArray, IgnoreNull, MaximumOperatorName, MinimumOperatorName, NotFound, SumOperatorName |
| Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
|---|
KeyPathSeparator |
| Constructor Summary | |
|---|---|
|
NSMutableArray()
Creates an empty mutable array. |
|
NSMutableArray(Collection collection)
Creates a mutable array from objects that implement the java.util.Collection interface. |
|
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(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(List list,
NSRange range,
boolean ignoreNull)
Creates a mutable array containing the objects from list in the range specified by range. |
|
NSMutableArray(NSArray otherArray)
One should use the mutableClone method instead. |
protected |
NSMutableArray(Object[] objects,
int rangeLocation,
int rangeLength,
boolean checkForNull,
boolean ignoreNull)
Creates a new Mutable Array |
| Method Summary | |
|---|---|
boolean |
add(Object element)
add is not a supported operation in NSArray |
void |
add(int index,
Object element)
add is not a supported operation in NSArray |
boolean |
addAll(Collection collection)
addAll is not a supported operation in NSArray |
boolean |
addAll(int index,
Collection collection)
addAll is not a supported operation in NSArray |
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. |
void |
clear()
Operation not supported |
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. |
ListIterator |
listIterator()
|
ListIterator |
listIterator(int index)
|
NSMutableArray |
mutableClone()
Creates a new NSMutableArray with the same elements as this array. |
Object |
remove(int index)
Removes the element at the specified position in this list. |
boolean |
remove(Object object)
Removes the first occurrence in this list of the specified element. |
boolean |
removeAll(Collection collection)
Operation not supported |
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. |
protected void |
removeRange(int fromIndex,
int toIndex)
Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. |
Object |
replaceObjectAtIndex(Object object,
int index)
Replaces the object at index with object. |
void |
replaceObjectAtIndex(int index,
Object object)
Deprecated. This method was provided for backward compatibility only. |
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. |
boolean |
retainAll(Collection collection)
Operation not supported |
Object |
set(int index,
Object element)
|
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. |
List |
subList(int fromIndex,
int toIndex)
Create a linked sublist. |
| 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 array
public 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 objectsNSMutableArray.mutableClone()
public NSMutableArray(List list,
NSRange range,
boolean ignoreNull)
list 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.
list - object that implements the List interfacerange - 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.Vectorpublic NSMutableArray(Collection collection)
java.util.Collection interface.
collection - object that implements the Collection interface
IllegalArgumentException - if a null element exists in List or List parameter is null.List
protected NSMutableArray(Object[] objects,
int rangeLocation,
int rangeLength,
boolean checkForNull,
boolean ignoreNull)
objects - rangeLocation - rangeLength - checkForNull - ignoreNull - | Method Detail |
|---|
public 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 addObject(Object object)
object at the end of this array.
object - the object to be inserted
IllegalArgumentException - if object is nullpublic 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 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 array
@Deprecated
public 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 indexNSMutableArray.replaceObjectAtIndex(Object, int)
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 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
IllegalArgumentException - if the array is empty or if index is beyond the end of the arraypublic void removeAllObjects()
public void sortUsingComparator(NSComparator comparator)
throws NSComparator.ComparisonException
comparator.
comparator - determines sorting behavior
NSComparator.ComparisonException - if comparator cannot sort these elements
IllegalArgumentException - if comparator is nullNSArray.sortedArrayUsingComparator(com.webobjects.foundation.NSComparator),
NSComparatorpublic void addObjectsFromArray(NSArray otherArray)
otherArray to the end of the this array.
otherArray - the objects to be appended to this array
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 Object removeLastObject()
null if the array is empty.
nullpublic 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 nullNSMutableArray.removeObjectAtIndex(int),
NSArray.indexOfObject(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 boundsNSMutableArray.removeObject(Object, NSRange)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 nullNSMutableArray.removeObject(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 boundsNSMutableArray.removeIdenticalObject(Object)public 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 removedNSMutableArray.removeObjects(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 removedNSMutableArray.removeObject(Object)public void removeObjectsInRange(NSRange range)
removeObjectAtIndex.
range - the range specified
IllegalArgumentException - if range is out of boundsNSMutableArray.removeObjectAtIndex(int)
protected void removeRange(int fromIndex,
int toIndex)
This method is called by the clear operation on this list and its subLists. Overriding this method to take advantage of the internals of the list implementation can substantially improve the performance of the clear operation on this list and its subLists.
This implementation gets a list iterator positioned before fromIndex, and repeatedly calls ListIterator.next followed by ListIterator.remove until the entire range has been removed. Note: if ListIterator.remove requires linear time, this implementation requires quadratic time.
fromIndex - index of first element to be removed.toIndex - index after last element to be removed.public Object clone()
clone in class NSArrayNSMutableArray.immutableClone(),
NSMutableArray.mutableClone(),
Object.clone()public NSArray immutableClone()
immutableClone in class NSArrayNSMutableArray.mutableClone(),
NSMutableArray.clone()public NSMutableArray mutableClone()
mutableClone in class NSArrayNSMutableArray.immutableClone(),
NSMutableArray.clone()public Object remove(int index)
remove in interface Listremove in class NSArrayindex - the index of the element to removed.
UnsupportedOperationException - if the remove method is not supported by this list.
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).List.remove(int)public boolean remove(Object object)
remove in interface Collectionremove in interface Listremove in class NSArrayobject - element to be removed from this list, if present.
ClassCastException - if the type of the specified element is incompatible with this list (optional).
NullPointerException - if the specified element is null and this list does not support null elements (optional).
UnsupportedOperationException - if the remove method is not supported by this list.List.remove(Object)public void clear()
NSArray
clear in interface Collectionclear in interface Listclear in class NSArrayList.clear(),
NSMutableArray.removeAllObjects()public boolean retainAll(Collection collection)
NSArray
retainAll in interface CollectionretainAll in interface ListretainAll in class NSArrayList.retainAll(java.util.Collection)public boolean removeAll(Collection collection)
NSArray
removeAll in interface CollectionremoveAll in interface ListremoveAll in class NSArrayList.removeAll(java.util.Collection)
public void add(int index,
Object element)
NSArray
add in interface Listadd in class NSArrayList.add(int, Object)public boolean add(Object element)
NSArray
add in interface Collectionadd in interface Listadd in class NSArrayelement - -
object to addList.add(Object)public boolean addAll(Collection collection)
NSArray
addAll in interface CollectionaddAll in interface ListaddAll in class NSArraycollection - -
collection to addList.addAll(Collection)
public boolean addAll(int index,
Collection collection)
NSArray
addAll in interface ListaddAll in class NSArrayindex - -
index of element to addcollection - -
collection to addList.addAll(int, Collection)
public Object set(int index,
Object element)
set in interface Listset in class NSArrayIndexOutOfBoundsException - if (index < 0 || index >= size())List.set(int, E)
public List subList(int fromIndex,
int toIndex)
Note: This list does not implement the NSMutableArray protocol
subList in interface ListsubList in class NSArrayIndexOutOfBoundsException - if index values fail the condition (fromIndex < 0 || toIndex > size || fromIndex > toIndex)List.subList(int, int)public ListIterator listIterator(int index)
listIterator in interface ListlistIterator in class NSArrayindex - of first element to be returned from the list iterator (by a call to the next method).listIterator(int)public ListIterator listIterator()
listIterator in interface ListlistIterator in class NSArraylistIterator()
|
Last updated June 2008 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||