|
WebObjects 5.4.1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.webobjects.foundation.NSArray<E>
com.webobjects.foundation.NSMutableArray<E>
E - public class NSMutableArray<E>
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(E, int),
removeAllObjects(),
removeObjectAtIndex(int),
replaceObjectAtIndex(Object, int),
setArray(com.webobjects.foundation.NSArray),
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 |
| Nested classes/interfaces inherited from interface com.webobjects.foundation.NSKeyValueCoding |
|---|
NSKeyValueCoding.ErrorHandling, NSKeyValueCoding.MapImplementation, NSKeyValueCoding.Null<T>, NSKeyValueCoding.UnknownKeyException, NSKeyValueCoding.ValueAccessor |
| 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 |
| Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding |
|---|
NullValue |
| Constructor Summary | |
|---|---|
|
NSMutableArray()
Creates an empty mutable array. |
|
NSMutableArray(Collection<? extends E> collection)
Creates a mutable array from objects that implement the java.util.Collection interface. |
|
NSMutableArray(E object)
Creates a mutable array containing the single element object. |
|
NSMutableArray(E[] objects)
Creates a mutable array containing objects. |
|
NSMutableArray(E[] 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<? extends E> list,
NSRange range,
boolean ignoreNull)
Creates a mutable array containing the objects from list in the range specified by range. |
|
NSMutableArray(NSArray<? extends E> 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(E element)
add is not a supported operation in NSArray |
void |
add(int index,
E element)
add is not a supported operation in NSArray |
boolean |
addAll(Collection<? extends E> collection)
addAll is not a supported operation in NSArray |
boolean |
addAll(int index,
Collection<? extends E> 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<? extends E> 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<E> |
immutableClone()
Creates a new NSArray with the same elements as this array. |
void |
insertObjectAtIndex(E object,
int index)
Inserts object into this array at index. |
ListIterator<E> |
listIterator()
|
ListIterator<E> |
listIterator(int index)
|
NSMutableArray<E> |
mutableClone()
Creates a new NSMutableArray with the same elements as this array. |
E |
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. |
E |
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(E object,
int index)
Replaces the object at index with object. |
void |
replaceObjectAtIndex(int index,
E object)
Deprecated. This method was provided for backward compatibility only. |
void |
replaceObjectsInRange(NSRange range,
NSArray<E> 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 |
E |
set(int index,
E 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<E> |
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(E object)
object.
object - the single element contained in the mutable arraypublic NSMutableArray(E[] objects)
objects.
objects - the objects contained in the mutable array
public NSMutableArray(E[] 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<? extends E> otherArray)
mutableClone method instead. Creates a mutable array containing the objects in otherArray.
otherArray - contains the objectsmutableClone()
public NSMutableArray(List<? extends E> 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<? extends E> 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(E 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,
E 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 insertObjectAtIndex(E 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 E 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,
NSComparatorpublic void addObjectsFromArray(NSArray<? extends E> otherArray)
otherArray to the end of the this array.
otherArray - the objects to be appended to this array
public void replaceObjectsInRange(NSRange range,
NSArray<E> 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 nullremoveObjectAtIndex(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 boundsremoveObject(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 nullremoveObject(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(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 removedremoveObjects(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(Object)public void removeObjectsInRange(NSRange range)
removeObjectAtIndex.
range - the range specified
IllegalArgumentException - if range is out of boundsremoveObjectAtIndex(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 NSArray<E>immutableClone(),
mutableClone(),
Object.clone()public NSArray<E> immutableClone()
immutableClone in class NSArray<E>mutableClone(),
clone()public NSMutableArray<E> mutableClone()
mutableClone in class NSArray<E>immutableClone(),
clone()public E remove(int index)
remove in interface List<E>remove in class NSArray<E>index - 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 Collection<E>remove in interface List<E>remove in class NSArray<E>object - 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 Collection<E>clear in interface List<E>clear in class NSArray<E>List.clear(),
removeAllObjects()public boolean retainAll(Collection<?> collection)
NSArray
retainAll in interface Collection<E>retainAll in interface List<E>retainAll in class NSArray<E>List.retainAll(java.util.Collection>)public boolean removeAll(Collection<?> collection)
NSArray
removeAll in interface Collection<E>removeAll in interface List<E>removeAll in class NSArray<E>List.removeAll(java.util.Collection>)
public void add(int index,
E element)
NSArray
add in interface List<E>add in class NSArray<E>List.add(int, Object)public boolean add(E element)
NSArray
add in interface Collection<E>add in interface List<E>add in class NSArray<E>element - -
object to addList.add(Object)public boolean addAll(Collection<? extends E> collection)
NSArray
addAll in interface Collection<E>addAll in interface List<E>addAll in class NSArray<E>collection - -
collection to addList.addAll(Collection)
public boolean addAll(int index,
Collection<? extends E> collection)
NSArray
addAll in interface List<E>addAll in class NSArray<E>index - -
index of element to addcollection - -
collection to addList.addAll(int, Collection)
public E set(int index,
E element)
set in interface List<E>set in class NSArray<E>IndexOutOfBoundsException - if (index < 0 || index >= size())List.set(int, E)
public List<E> subList(int fromIndex,
int toIndex)
Note: This list does not implement the NSMutableArray protocol
subList in interface List<E>subList in class NSArray<E>IndexOutOfBoundsException - if index values fail the condition (fromIndex < 0 || toIndex > size || fromIndex > toIndex)List.subList(int, int)public ListIterator<E> listIterator(int index)
listIterator in interface List<E>listIterator in class NSArray<E>index - of first element to be returned from the list iterator (by a call to the next method).listIterator(int)public ListIterator<E> listIterator()
listIterator in interface List<E>listIterator in class NSArray<E>listIterator()
|
Last updated Wednesday, January 23, 2008 14:25 PST | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||