public interface SparseArray<T>
Although interfaces cannot enforce constructors, it is suggested that instances implement an additional constructor with an array parameter of the required type. This constructor should make a copy of the array so that changes to one are not propagated.
In addition, it is suggested that instances that wrap Java primitive-type
arrays provide two additional methods, getPrimitive
and setPrimitive
, which operate directly on the primitive types rather than
their object equivalents. This allows users to save any performance costs
from auto-boxing the primitives.
Modifier and Type | Method and Description |
---|---|
int |
cardinality()
Returns the number of non-zero values in this sparse array
|
T |
get(int index)
Returns the value of this array at the index.
|
int[] |
getElementIndices()
Returns the indices of the array that contain non-
null values. |
int |
length()
Returns length of this array.
|
void |
set(int index,
T obj)
Sets the object as the value at the index.
|
<E> E[] |
toArray(E[] array)
Fills the provided array with the values contained in this array that fit
within the length of the provided array.
|
int cardinality()
T get(int index)
index
- the position in the arrayint[] getElementIndices()
null
values.int length()
void set(int index, T obj)
index
- an index in the arrayobj
- the value<E> E[] toArray(E[] array)
ClassCastException
- if the contents of this sparse array are not
compatible with the type of the provided arrayCopyright © 2012. All Rights Reserved.