Project Wonder 2.0

er.extensions
Class ERXMutableArray

java.lang.Object
  extended bycom.webobjects.foundation.NSArray
      extended bycom.webobjects.foundation.NSMutableArray
          extended byer.extensions.ERXMutableArray
All Implemented Interfaces:
_NSFoundationCollection, Cloneable, Collection, List, NSCoding, NSKeyValueCoding, NSKeyValueCodingAdditions, Serializable

public class ERXMutableArray
extends NSMutableArray
implements List

Custom subclass of NSMutableArray. Implements List and can be used as a EOF custom value class because it can automatically en- and decode an NSMutableArray as blob into a database. NOTE: As the List implementation is based on the NSMutableArray implementation, care must be taken when subclassing; it is best if you use only List-methods when extending List-methods and NSArray methods in other cases. Otherwise you will most likely get into stack overflows. NOTE: List allows for NULL values, NSMutableArray does not. Therefore you can't use NULL objects. The ERPrototype name is mutableArray

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class com.webobjects.foundation.NSArray
NSArray.Operator
 
Nested classes inherited from class com.webobjects.foundation.NSCoding
NSCoding._BigDecimalSupport, NSCoding._BigIntegerSupport, NSCoding._BooleanSupport, NSCoding._ByteSupport, NSCoding._CharacterSupport, NSCoding._DateSupport, NSCoding._DoubleSupport, NSCoding._FloatSupport, NSCoding._IntegerSupport, NSCoding._LongSupport, NSCoding._NumberSupport, NSCoding._ShortSupport, NSCoding._StringSupport, NSCoding.Support
 
Nested classes inherited from class com.webobjects.foundation.NSKeyValueCoding
NSKeyValueCoding._BooleanFieldBinding, NSKeyValueCoding._BooleanMethodBinding, NSKeyValueCoding._FieldBinding, NSKeyValueCoding._ForwardingBinding, NSKeyValueCoding._KeyBinding, NSKeyValueCoding._KeyBindingCreation, NSKeyValueCoding._MethodBinding, NSKeyValueCoding._NumberFieldBinding, NSKeyValueCoding._NumberMethodBinding, NSKeyValueCoding._ReflectionKeyBindingCreation, 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
protected  int modCount
          The number of times this list has been structurally modified.
static long serialVersionUID
           
 
Fields inherited from class com.webobjects.foundation.NSMutableArray
_CLASS
 
Fields inherited from class com.webobjects.foundation.NSArray
_capacity, _count, _hashCache, _NSArrayClassHashCode, _objects, _objectsCache, AverageOperatorName, CountOperatorName, EmptyArray, MaximumOperatorName, MinimumOperatorName, NotFound, SumOperatorName
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding
NullValue
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions
_KeyPathSeparatorChar, KeyPathSeparator
 
Constructor Summary
ERXMutableArray()
           
ERXMutableArray(Collection c)
           
ERXMutableArray(int i)
           
ERXMutableArray(NSArray array)
           
ERXMutableArray(Object obj)
           
ERXMutableArray(Object[] aobj)
           
ERXMutableArray(Object[] objects, NSRange range)
           
ERXMutableArray(Vector vector, NSRange range, boolean flag)
           
 
Method Summary
 void add(int index, Object element)
          Inserts the specified element at the specified position in this list.
 boolean add(Object o)
          Appends the specified element to the end of this list.
 boolean addAll(Collection c)
          Adds all of the elements in the specified collection to this collection (optional operation).
 boolean addAll(int index, Collection c)
          Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
 void clear()
          Removes all of the elements from this collection (optional operation).
 boolean contains(Object elem)
          Returns true if this list contains the specified element.
 boolean containsAll(Collection c)
          Returns true if this collection contains all of the elements in the specified collection.
 void ensureCapacity(int minCapacity)
          Increases the capacity of this ERXMutableArray instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
static ERXMutableArray fromBlob(NSData d)
           
static ERXMutableArray fromPropertyList(String arrayAsString)
           
 Object get(int index)
          Returns the element at the specified position in this list.
 int indexOf(Object elem)
          Searches for the first occurence of the given argument, testing for equality using the equals method.
 boolean isEmpty()
          Tests if this list has no elements.
 Iterator iterator()
          Returns an iterator over the elements in this list in proper sequence.
 int lastIndexOf(Object elem)
          Returns the index of the last occurrence of the specified object in this list.
 ListIterator listIterator()
          Returns an iterator of the elements in this list (in proper sequence).
 ListIterator listIterator(int index)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in the list.
 NSMutableArray mutableClone()
           
 Object remove(int index)
          Removes the element at the specified position in this list.
 boolean remove(Object o)
          Removes a single instance of the specified element from this collection, if it is present (optional operation).
 boolean removeAll(Collection c)
          Removes from this collection all of its elements that are contained in the specified collection (optional operation).
protected  void removeRange(int fromIndex, int toIndex)
          Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.
 boolean retainAll(Collection c)
          Retains only the elements in this collection that are contained in the specified collection (optional operation).
 Object set(int index, Object element)
          Replaces the element at the specified position in this list with the specified element.
 int size()
          Returns the number of elements in this list.
 List subList(int fromIndex, int toIndex)
          Returns a view of the portion of this list between fromIndex, inclusive, and toIndex, exclusive.
 Object[] toArray()
          Returns an array containing all of the elements in this list in the correct order.
 Object[] toArray(Object[] a)
          Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array.
 NSData toBlob()
           
static NSData toBlob(ERXMutableArray d)
           
 String toPropertyList()
           
static String toPropertyList(ERXMutableArray array)
           
 String[] toStringArray()
           
 void trimToSize()
          Trims the capacity of this ERXMutableArray instance to be the list's current size.
 
Methods inherited from class com.webobjects.foundation.NSMutableArray
_moveObjectAtIndexToIndex, addObject, addObjects, addObjectsFromArray, clone, immutableClone, insertObjectAtIndex, removeAllObjects, removeIdenticalObject, removeIdenticalObject, removeLastObject, removeObject, removeObject, removeObjectAtIndex, removeObjects, removeObjectsInArray, removeObjectsInRange, replaceObjectAtIndex, replaceObjectAtIndex, replaceObjectsInRange, setArray, sortUsingComparator
 
Methods inherited from class com.webobjects.foundation.NSArray
_ensureCapacity, _initializeWithCapacity, _mustRecomputeHash, _mutableComponentsSeparatedByString, _setMustRecomputeHash, _shallowHashCode, arrayByAddingObject, arrayByAddingObjectsFromArray, classForCoder, componentsJoinedByString, componentsSeparatedByString, containsObject, count, decodeObject, encodeWithCoder, equals, firstObjectCommonWithArray, getObjects, getObjects, hashCode, indexOfIdenticalObject, indexOfIdenticalObject, indexOfObject, indexOfObject, isEqualToArray, lastObject, makeObjectsPerformSelector, objectAtIndex, objectEnumerator, objects, objects, objectsNoCopy, operatorForKey, operatorNames, removeOperatorForKey, reverseObjectEnumerator, setOperatorForKey, sortedArrayUsingComparator, sortedArrayUsingSelector, subarrayWithRange, takeValueForKey, takeValueForKeyPath, toString, valueForKey, valueForKeyPath, vector
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values

modCount

protected transient int modCount
The number of times this list has been structurally modified. Structural modifications are those that change the size of the list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.

This field is used by the iterator and list iterator implementation returned by the iterator and listIterator methods. If the value of this field changes unexpectedly, the iterator (or list iterator) will throw a ConcurrentModificationException in response to the next, remove, previous, set or add operations. This provides fail-fast behavior, rather than non-deterministic behavior in the face of concurrent modification during iteration.

Use of this field by subclasses is optional. If a subclass wishes to provide fail-fast iterators (and list iterators), then it merely has to increment this field in its add(int, Object) and remove(int) methods (and any other methods that it overrides that result in structural modifications to the list). A single call to add(int, Object) or remove(int) must add no more than one to this field, or the iterators (and list iterators) will throw bogus ConcurrentModificationExceptions. If an implementation does not wish to provide fail-fast iterators, this field may be ignored.

Constructor Detail

ERXMutableArray

public ERXMutableArray()

ERXMutableArray

public ERXMutableArray(Collection c)

ERXMutableArray

public ERXMutableArray(NSArray array)

ERXMutableArray

public ERXMutableArray(int i)

ERXMutableArray

public ERXMutableArray(Object obj)

ERXMutableArray

public ERXMutableArray(Object[] aobj)

ERXMutableArray

public ERXMutableArray(Object[] objects,
                       NSRange range)

ERXMutableArray

public ERXMutableArray(Vector vector,
                       NSRange range,
                       boolean flag)
Method Detail

toBlob

public static NSData toBlob(ERXMutableArray d)
                     throws Exception
Throws:
Exception

fromBlob

public static ERXMutableArray fromBlob(NSData d)
                                throws Exception
Throws:
Exception

fromPropertyList

public static ERXMutableArray fromPropertyList(String arrayAsString)

toPropertyList

public static String toPropertyList(ERXMutableArray array)

toBlob

public NSData toBlob()
              throws Exception
Throws:
Exception

toPropertyList

public String toPropertyList()

mutableClone

public NSMutableArray mutableClone()

remove

public boolean remove(Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the collection contains one or more such elements. Returns true if the collection contained the specified element (or equivalently, if the collection changed as a result of the call).

This implementation iterates over the collection looking for the specified element. If it finds the element, it removes the element from the collection using the iterator's remove method.

Note that this implementation throws an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection contains the specified object.

Specified by:
remove in interface List
Parameters:
o - element to be removed from this collection, if present.
Returns:
true if the collection contained the specified element.
Throws:
UnsupportedOperationException - if the remove method is not supported by this collection.

containsAll

public boolean containsAll(Collection c)
Returns true if this collection contains all of the elements in the specified collection.

This implementation iterates over the specified collection, checking each element returned by the iterator in turn to see if it's contained in this collection. If all elements are so contained true is returned, otherwise false.

Specified by:
containsAll in interface List
Parameters:
c - collection to be checked for containment in this collection.
Returns:
true if this collection contains all of the elements in the specified collection.
Throws:
NullPointerException - if the specified collection is null.
See Also:
contains(Object)

addAll

public boolean addAll(Collection c)
Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.)

This implementation iterates over the specified collection, and adds each object returned by the iterator to this collection, in turn.

Note that this implementation will throw an UnsupportedOperationException unless add is overridden (assuming the specified collection is non-empty).

Specified by:
addAll in interface List
Parameters:
c - collection whose elements are to be added to this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
UnsupportedOperationException - if this collection does not support the addAll method.
NullPointerException - if the specified collection is null.
See Also:
add(Object)

removeAll

public boolean removeAll(Collection c)
Removes from this collection all of its elements that are contained in the specified collection (optional operation).

This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's so contained, it's removed from this collection with the iterator's remove method.

Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method and this collection contains one or more elements in common with the specified collection.

Specified by:
removeAll in interface List
Parameters:
c - elements to be removed from this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
UnsupportedOperationException - if the removeAll method is not supported by this collection.
NullPointerException - if the specified collection is null.
See Also:
remove(Object), contains(Object)

retainAll

public boolean retainAll(Collection c)
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.

This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's not so contained, it's removed from this collection with the iterator's remove method.

Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method and this collection contains one or more elements not present in the specified collection.

Specified by:
retainAll in interface List
Parameters:
c - elements to be retained in this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
UnsupportedOperationException - if the retainAll method is not supported by this Collection.
NullPointerException - if the specified collection is null.
See Also:
remove(Object), contains(Object)

trimToSize

public void trimToSize()
Trims the capacity of this ERXMutableArray instance to be the list's current size. An application can use this operation to minimize the storage of an ERXMutableArray instance.


ensureCapacity

public void ensureCapacity(int minCapacity)
Increases the capacity of this ERXMutableArray instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

Parameters:
minCapacity - the desired minimum capacity.

size

public int size()
Returns the number of elements in this list.

Specified by:
size in interface List
Returns:
the number of elements in this list.

isEmpty

public boolean isEmpty()
Tests if this list has no elements.

Specified by:
isEmpty in interface List
Returns:
true if this list has no elements; false otherwise.

contains

public boolean contains(Object elem)
Returns true if this list contains the specified element.

Specified by:
contains in interface List
Parameters:
elem - element whose presence in this List is to be tested.
Returns:
true if the specified element is present; false otherwise.

indexOf

public int indexOf(Object elem)
Searches for the first occurence of the given argument, testing for equality using the equals method.

Specified by:
indexOf in interface List
Parameters:
elem - an object.
Returns:
the index of the first occurrence of the argument in this list; returns -1 if the object is not found.
See Also:
Object.equals(Object)

lastIndexOf

public int lastIndexOf(Object elem)
Returns the index of the last occurrence of the specified object in this list.

Specified by:
lastIndexOf in interface List
Parameters:
elem - the desired element.
Returns:
the index of the last occurrence of the specified object in this list; returns -1 if the object is not found.

toArray

public Object[] toArray()
Returns an array containing all of the elements in this list in the correct order.

Specified by:
toArray in interface List
Returns:
an array containing all of the elements in this list in the correct order.

toArray

public Object[] toArray(Object[] a)
Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.

If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.

Specified by:
toArray in interface List
Parameters:
a - the array into which the elements of the list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of the list.
Throws:
ArrayStoreException - if the runtime type of a is not a supertype of the runtime type of every element in this list.

get

public Object get(int index)
Returns the element at the specified position in this list.

Specified by:
get in interface List
Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.
Throws:
IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).

set

public Object set(int index,
                  Object element)
Replaces the element at the specified position in this list with the specified element.

Specified by:
set in interface List
Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.
Throws:
IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

add

public boolean add(Object o)
Appends the specified element to the end of this list.

Specified by:
add in interface List
Parameters:
o - element to be appended to this list.
Returns:
true (as per the general contract of Collection.add).

add

public void add(int index,
                Object element)
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Specified by:
add in interface List
Parameters:
index - index at which the specified element is to be inserted.
element - element to be inserted.
Throws:
IndexOutOfBoundsException - if index is out of range (index < 0 || index > size()).

remove

public Object remove(int index)
Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).

Specified by:
remove in interface List
Parameters:
index - the index of the element to removed.
Returns:
the element that was removed from the list.
Throws:
IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

clear

public void clear()
Removes all of the elements from this collection (optional operation). The collection will be empty after this call returns (unless it throws an exception).

This implementation calls removeRange(0, size()).

Note that this implementation throws an UnsupportedOperationException unless remove(int index) or removeRange(int fromIndex, int toIndex) is overridden.

Specified by:
clear in interface List
Throws:
UnsupportedOperationException - if the clear method is not supported by this Collection.

addAll

public boolean addAll(int index,
                      Collection c)
Inserts all of the elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified collection's iterator. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)

This implementation gets an iterator over the specified collection and iterates over it, inserting the elements obtained from the iterator into this list at the appropriate position, one at a time, using add(int, Object). Many implementations will override this method for efficiency.

Note that this implementation throws an UnsupportedOperationException unless add(int, Object) is overridden.

Specified by:
addAll in interface List
Parameters:
index - index at which to insert the first element from the specified collection.
c - elements to be inserted into this List.
Returns:
true if this list changed as a result of the call.
Throws:
UnsupportedOperationException - if the addAll method is not supported by this list.
ClassCastException - if the class of an element of the specified collection prevents it from being added to this List.
IllegalArgumentException - some aspect an element of the specified collection prevents it from being added to this List.
IndexOutOfBoundsException - index out of range (index < 0 || index > size()).
NullPointerException - if the specified collection is null.

iterator

public Iterator iterator()
Returns an iterator over the elements in this list in proper sequence.

This implementation returns a straightforward implementation of the iterator interface, relying on the backing list's size(), get(int), and remove(int) methods.

Note that the iterator returned by this method will throw an UnsupportedOperationException in response to its remove method unless the list's remove(int) method is overridden.

This implementation can be made to throw runtime exceptions in the face of concurrent modification, as described in the specification for the (protected) modCount field.

Specified by:
iterator in interface List
Returns:
an iterator over the elements in this list in proper sequence.
See Also:
modCount

listIterator

public ListIterator listIterator()
Returns an iterator of the elements in this list (in proper sequence). This implementation returns listIterator(0).

Specified by:
listIterator in interface List
Returns:
an iterator of the elements in this list (in proper sequence).
See Also:
listIterator(int)

listIterator

public ListIterator listIterator(int index)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to the next method. An initial call to the previous method would return the element with the specified index minus one.

This implementation returns a straightforward implementation of the ListIterator interface that extends the implementation of the Iterator interface returned by the iterator() method. The ListIterator implementation relies on the backing list's get(int), set(int, Object), add(int, Object) and remove(int) methods.

Note that the list iterator returned by this implementation will throw an UnsupportedOperationException in response to its remove, set and add methods unless the list's remove(int), set(int, Object), and add(int, Object) methods are overridden.

This implementation can be made to throw runtime exceptions in the face of concurrent modification, as described in the specification for the (protected) modCount field.

Specified by:
listIterator in interface List
Parameters:
index - index of the first element to be returned from the list iterator (by a call to the next method).
Returns:
a list iterator of the elements in this list (in proper sequence), starting at the specified position in the list.
Throws:
IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index > size()).
See Also:
modCount

subList

public List subList(int fromIndex,
                    int toIndex)
Returns a view of the portion of this list between fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by operating on a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:

     list.subList(from, to).clear();
 
Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList.

The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of the list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)

This implementation returns a list that subclasses ERXMutableArray. The subclass stores, in private fields, the offset of the subList within the backing list, the size of the subList (which can change over its lifetime), and the expected modCount value of the backing list. There are two variants of the subclass, one of which implements RandomAccess. If this list implements RandomAccess the returned list will be an instance of the subclass that implements RandomAccess.

The subclass's set(int, Object), get(int), add(int, Object), remove(int), addAll(int, Collection) and removeRange(int, int) methods all delegate to the corresponding methods on the backing abstract list, after bounds-checking the index and adjusting for the offset. The addAll(Collection c) method merely returns addAll(size, c).

The listIterator(int) method returns a "wrapper object" over a list iterator on the backing list, which is created with the corresponding method on the backing list. The iterator method merely returns listIterator(), and the size method merely returns the subclass's size field.

All methods first check to see if the actual modCount of the backing list is equal to its expected value, and throw a ConcurrentModificationException if it is not.

Specified by:
subList in interface List
Parameters:
fromIndex - low endpoint (inclusive) of the subList.
toIndex - high endpoint (exclusive) of the subList.
Returns:
a view of the specified range within this list.
Throws:
IndexOutOfBoundsException - endpoint index value out of range (fromIndex < 0 || toIndex > size)
IllegalArgumentException - endpoint indices out of order (fromIndex > toIndex)

removeRange

protected void removeRange(int fromIndex,
                           int toIndex)
Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the ERXMutableArray by (toIndex - fromIndex) elements. (If toIndex==fromIndex, this operation has no effect.)

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.

Parameters:
fromIndex - index of first element to be removed.
toIndex - index after last element to be removed.

toStringArray

public String[] toStringArray()

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.