|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface SparseArray
Sparsely Populated Array interface
| Method Summary | |
|---|---|
boolean |
add(Object o)
Appends the specified element to the end of this sparse array (optional operation). |
List |
asList()
A list backed up by the sparse array. |
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. |
Iterator |
iterator()
Returns an iterator over the elements in this sparse array (in proper sequence). |
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). |
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). |
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. |
| Methods inherited from interface java.util.Collection |
|---|
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray |
| Method Detail |
|---|
int size()
size in interface CollectionIterator iterator()
iterator in interface Collectioniterator in interface IterableList asList()
int start()
int end()
fromIndex is returned for
subarrays, 0 otherwise.Object get(int index)
index - index of element to return.
IndexOutOfBoundsException - if the index is out of range (index < 0).
Object set(int index,
Object element)
set(i,null) is equivalent to remove(i).
index - 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).void setAll(SparseArray t)
t - Entries to be stored in this sparse array.
UnsupportedOperationException - if the setAll 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 value in the specified sparse array
prevents it from being stored in this sparse array.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.
add in interface Collectiono - 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.Object remove(int index)
remove(i) is equivalent to set(i,null).
index - 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).int indexOf(Object o)
(o==null ? get(i)==null : o.equals(get(i))), or -1 if
there is no such index.
o - element to search for.
PopulationIterator populationIterator()
populationIterator(int),
start(),
end()PopulationIterator populationIterator(int fromIndex)
populationIterator(),
end()SortedMap populationMap()
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 the sparse array returned by this method become undefined if the backing sparse array (i.e., this sparse array) is structurally modified in any way other than via the returned sparse array. (Structural modifications are those that change the size of this sparse array, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
fromIndex - low endpoint (inclusive) of the subArray.toIndex - high endpoint (exclusive) of the subArray.
IndexOutOfBoundsException - for an illegal endpoint index value (fromIndex < 0 ||
fromIndex > toIndex).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||