|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.openmdx.base.collection.AbstractSparseArray
public abstract class AbstractSparseArray
This class provides a skeletal implementation of the SparseArray interface to minimize the effort required to implement this interface backed by a data store.
The programmer needs only to extend this class and provide an implementation for the populationMap() method.
The programmer should generally provide a void (no argument) and collection constructor, as per the recommendation in the Collection interface specification. The documentation for each non-abstract methods in this class describes its implementation in detail. Each of these methods may be overridden if the collection being implemented admits a more efficient implementation.
| Constructor Summary | |
|---|---|
protected |
AbstractSparseArray()
Constructs an empty sparse array. |
| Method Summary | |
|---|---|
boolean |
add(Object o)
Appends the specified element to the end of this sparse array (optional operation). |
boolean |
addAll(Collection c)
Adds all of the elements in the specified collection to this collection (optional operation). |
List |
asList()
A list backed up by the sparse array. |
void |
clear()
Removes all of the elements from this collection (optional operation). |
boolean |
contains(Object o)
Returns true if this collection contains the specified element. |
boolean |
containsAll(Collection c)
Returns true if this collection contains all of the elements in the specified collection. |
int |
end()
Return the index where add() would insert an element. |
Object |
get(int index)
Returns the element at the specified position in this sparse array. |
int |
indexOf(Object o)
Returns the index in this sparse array of the first occurrence of the specified element, or -1 if this sparse array does not contain this element. |
boolean |
isEmpty()
Returns true if this collection contains no elements. |
Iterator |
iterator()
Returns an iterator over the elements in this sparse array (in proper sequence). |
protected int |
lowerBound()
The lower bound is relevant for the end(), add(Object element) and asList() methods. |
PopulationIterator |
populationIterator()
Returns an iterator for the populated elements in this sparse array (in proper sequence). |
PopulationIterator |
populationIterator(int fromIndex)
Returns an iterator for the populated elements in this sparse array (in proper sequence). |
abstract SortedMap |
populationMap()
Returns a map view of this sparse array's populated elements. |
Object |
remove(int index)
Removes the element at the specified position in this sparse array (optional operation). |
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). |
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 sparse array with the specified element (optional operation). |
void |
setAll(SparseArray t)
Copies all of the entries from the specified sparse array to this sparse array (optional operation). |
int |
size()
Returns the number of (non-null) elements in this sparse array. |
int |
start()
Return the index of the first populated element in the sparse array or -1 if the sparse array is empty. |
SparseArray |
subArray(int fromIndex,
int toIndex)
Returns a view of the portion of this sparse array between the specified fromIndex, inclusive, and toIndex, exclusive. |
Object[] |
toArray()
Returns an array containing all of the elements in this collection. |
Object[] |
toArray(Object[] a)
Returns an array with a runtime type is that of the specified array and that contains all of the elements in this collection. |
String |
toString()
Returns a string representation of this collection. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
|---|
equals, hashCode |
| Constructor Detail |
|---|
protected AbstractSparseArray()
| Method Detail |
|---|
protected int lowerBound()
end(),
asList(),
add(Object)public abstract SortedMap populationMap()
populationMap in interface SparseArraypublic int size()
This implementaion returns the population map's size.
size in interface Collectionsize in interface SparseArraypublic Iterator iterator()
This implementaion returns an iterator over the population map's values.
iterator in interface Iterableiterator in interface Collectioniterator in interface SparseArraypublic List asList()
asList in interface SparseArraypublic int start()
This implementation returns the population map's first key unless it is empty.
start in interface SparseArraypublic int end()
This implementation returns the population map's last key unless it is empty.
end in interface SparseArrayfromIndex is returned for
subarrays, 0 otherwise.public Object get(int index)
This implementation returns the corresponding element from the population map.
get in interface SparseArrayindex - index of element to return.
IndexOutOfBoundsException - if the index is out of range (index < 0).
public Object set(int index,
Object element)
set(i,null) is equivalent to remove(i).
This implementation puts the corresponding element into the population map unless it is null.
set in interface SparseArrayindex - index of element to replace.element - element to be stored at the specified position.
UnsupportedOperationException - if the set method is not supported by this sparse array.
ClassCastException - - if the class of the specified element
prevents it from being added to this sparse array.
IllegalArgumentException - if some aspect of the specified element prevents it from
being added to this sparse array.
IndexOutOfBoundsException - if the index is out of range (index < 0).public void setAll(SparseArray t)
This implementation calls the set(int index, Object element) method for each entry.
setAll in interface SparseArrayt - Entries to be stored in this map.
UnsupportedOperationException - if the sttAll method is not supported by this sparse
array.
ClassCastException - if the class of a value in the specified sparse array
prevents it from being stored in this sparse array.
IllegalArgumentException - some aspect of a key or value in the specified map
prevents it from being stored in this map.
NullPointerException - this map does not permit null keys or values, and the
specified key or value is null.public boolean add(Object o)
Adding a null value to a sparse array does nothing.
Sparse arrays that support this operation may place limitations on what elements may be added to this sparse array. In particular, some sparse arrays will impose restrictions on the type of elements that may be added. Sparse array classes should clearly specify in their documentation any restrictions on what elements may be added.
This implementation puts the element at position end() into the sparse array unless it is null.
add in interface Collectionadd in interface SparseArrayo - element to be appended to this sparse array.
UnsupportedOperationException - if the add method is not supported by this sparse array.
ClassCastException - if the class of the specified element prevents it from
being added to this sparse array.
IllegalArgumentException - if some aspect of this element prevents it from being
added to this collection.public Object remove(int index)
remove(i) is equivalent to set(i,null).
This implementation removes the element from the population.
remove in interface SparseArrayindex - the index of the element to removed.
UnsupportedOperationException - if the remove method is not supported by this sparse
array.
IndexOutOfBoundsException - if the index is out of range (index < 0).public int indexOf(Object o)
(o==null ? get(i)==null : o.equals(get(i))), or -1 if
there is no such index.
indexOf in interface SparseArrayo - element to search for.
public PopulationIterator populationIterator()
populationIterator in interface SparseArraypopulationIterator(int),
start(),
end()public PopulationIterator populationIterator(int fromIndex)
This implementation iterates over the tail array starting at fromIndex.
populationIterator in interface SparseArraypopulationIterator(),
end()
public SparseArray subArray(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 sparse array can be used as a range operation by passing a subArray view instead of a whole sparse array. For example, the following idiom removes a range of elements from a sparse array:
list.subArray(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 subArray.
The semantics of this 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 this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
subArray in interface SparseArrayfromIndex - low endpoint (inclusive) of the subArray.toIndex - high endpoint (exclusive) of the subArray.
IndexOutOfBoundsException - for an illegal endpoint index value (fromIndex < 0 ||
fromIndex > toIndex).public boolean isEmpty()
This implementation checks whether the population map is empty.
isEmpty in interface Collectionpublic boolean contains(Object o)
This implementation checks whether the object is among the population map's values.
contains in interface Collectiono - object to be checked for containment in this collection.
public Object[] toArray()
This implementation allocates the array to be returned, and iterates over the elements in the collection, storing each object reference in the next consecutive element of the array, starting with element 0.
toArray in interface Collectionpublic Object[] toArray(Object[] a)
If the collection fits in the specified array with room to spare (i.e., the array has more elements than the collection), 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 collection only if the caller knows that the collection does not contain any null elements.)
If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
This implementation checks if the array is large enough to contain the collection; if not, it allocates a new array of the correct size and type (using reflection). Then, it iterates over the collection, storing each object reference in the next consecutive element of the array, starting with element 0. If the array is larger than the collection, a null is stored in the first location after the end of the collection.
toArray in interface Collectiona - the array into which the elements of the collection are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.
NullPointerException - if the specified array is null.
ArrayStoreException - if the runtime type of the specified array
is not a supertype of the runtime type of every element in this
collection.public boolean remove(Object o)
This implementation removes the object from the population map's values.
remove in interface Collectiono - 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 checks whether all the collection's elements are among population map's values.
containsAll in interface Collectionc - collection to be checked for containment in this collection.
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.
addAll in interface Collectionc - collection whose elements are to be added to this collection.
UnsupportedOperationException - if the addAll method is
not supported by this collection.add(Object)public boolean removeAll(Collection c)
This implementation removes all elements in the specified collection from the population map's values.
removeAll in interface Collectionc - elements to be removed from this collection.
UnsupportedOperationException - removeAll is not supported
by this collection.remove(Object),
contains(Object)public boolean retainAll(Collection c)
This implementation removes all elements not contained in the specified collection from the population map's values.
retainAll in interface Collectionc - elements to be retained in this collection.
UnsupportedOperationException - if the retainAll method
is not supported by this collection.remove(Object),
contains(Object)public void clear()
This implementation clears the population map.
Note that this implementation will throw an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method.
clear in interface CollectionUnsupportedOperationException - if the remove method is
not supported by this collection.public String toString()
This implementation creates an empty string buffer, appends a left square bracket, and iterates over the collection appending the string representation of each element in turn. After appending each element except the last, the string ", " is appended. Finally a right bracket is appended. A string is obtained from the string buffer, and returned.
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||