|
Project Wonder 2.0 | ||||||||||
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 er.extensions.ERXMutableArray
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
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.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 java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
equals, hashCode |
Field Detail |
public static final long serialVersionUID
protected transient int modCount
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 |
public ERXMutableArray()
public ERXMutableArray(Collection c)
public ERXMutableArray(NSArray array)
public ERXMutableArray(int i)
public ERXMutableArray(Object obj)
public ERXMutableArray(Object[] aobj)
public ERXMutableArray(Object[] objects, NSRange range)
public ERXMutableArray(Vector vector, NSRange range, boolean flag)
Method Detail |
public static NSData toBlob(ERXMutableArray d) throws Exception
Exception
public static ERXMutableArray fromBlob(NSData d) throws Exception
Exception
public static ERXMutableArray fromPropertyList(String arrayAsString)
public static String toPropertyList(ERXMutableArray array)
public NSData toBlob() throws Exception
Exception
public String toPropertyList()
public NSMutableArray mutableClone()
public boolean remove(Object o)
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.
remove
in interface List
o
- element to be removed from this collection, if present.
UnsupportedOperationException
- if the remove method is
not supported by this collection.public boolean containsAll(Collection c)
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.
containsAll
in interface List
c
- collection to be checked for containment in this collection.
NullPointerException
- if the specified collection is null.contains(Object)
public boolean addAll(Collection c)
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).
addAll
in interface List
c
- collection whose elements are to be added to this collection.
UnsupportedOperationException
- if this collection does not
support the addAll method.
NullPointerException
- if the specified collection is null.add(Object)
public boolean removeAll(Collection c)
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.
removeAll
in interface List
c
- elements to be removed from this collection.
UnsupportedOperationException
- if the removeAll method
is not supported by this collection.
NullPointerException
- if the specified collection is null.remove(Object)
,
contains(Object)
public boolean retainAll(Collection c)
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.
retainAll
in interface List
c
- elements to be retained in this collection.
UnsupportedOperationException
- if the retainAll method
is not supported by this Collection.
NullPointerException
- if the specified collection is null.remove(Object)
,
contains(Object)
public void trimToSize()
public void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacity.public int size()
size
in interface List
public boolean isEmpty()
isEmpty
in interface List
public boolean contains(Object elem)
contains
in interface List
elem
- element whose presence in this List is to be tested.
true
if the specified element is present;
false
otherwise.public int indexOf(Object elem)
indexOf
in interface List
elem
- an object.
Object.equals(Object)
public int lastIndexOf(Object elem)
lastIndexOf
in interface List
elem
- the desired element.
public Object[] toArray()
toArray
in interface List
public Object[] toArray(Object[] a)
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.
toArray
in interface List
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.
ArrayStoreException
- if the runtime type of a is not a supertype
of the runtime type of every element in this list.public Object get(int index)
get
in interface List
index
- index of element to return.
IndexOutOfBoundsException
- if index is out of range (index
< 0 || index >= size()).public Object set(int index, Object element)
set
in interface List
index
- index of element to replace.element
- element to be stored at the specified position.
IndexOutOfBoundsException
- if index out of range
(index < 0 || index >= size()).public boolean add(Object o)
add
in interface List
o
- element to be appended to this list.
public void add(int index, Object element)
add
in interface List
index
- index at which the specified element is to be inserted.element
- element to be inserted.
IndexOutOfBoundsException
- if index is out of range
(index < 0 || index > size()).public Object remove(int index)
remove
in interface List
index
- the index of the element to removed.
IndexOutOfBoundsException
- if index out of range (index
< 0 || index >= size()).public void clear()
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.
clear
in interface List
UnsupportedOperationException
- if the clear method is
not supported by this Collection.public boolean addAll(int index, Collection c)
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.
addAll
in interface List
index
- index at which to insert the first element from the
specified collection.c
- elements to be inserted into this List.
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.public Iterator iterator()
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.
iterator
in interface List
modCount
public ListIterator listIterator()
listIterator
in interface List
listIterator(int)
public ListIterator listIterator(int index)
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.
listIterator
in interface List
index
- index of the first element to be returned from the list
iterator (by a call to the next method).
IndexOutOfBoundsException
- if the specified index is out of
range (index < 0 || index > size()).modCount
public List subList(int fromIndex, int toIndex)
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.
subList
in interface List
fromIndex
- low endpoint (inclusive) of the subList.toIndex
- high endpoint (exclusive) of the subList.
IndexOutOfBoundsException
- endpoint index value out of range
(fromIndex < 0 || toIndex > size)
IllegalArgumentException
- endpoint indices out of order
(fromIndex > toIndex)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 String[] toStringArray()
|
Last updated: Do, Dez 9, 2004 12:46 PM CET | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |