public class SparseFloatArray
extends java.lang.Object
implements java.lang.Cloneable
android.util.SparseIntArray
Constructor and Description |
---|
SparseFloatArray()
Creates a new SparseFloatArray containing no mappings.
|
SparseFloatArray(int initialCapacity)
Creates a new SparseFloatArray containing no mappings that will not require any additional
memory allocation to store the specified number of mappings.
|
Modifier and Type | Method and Description |
---|---|
void |
append(int key,
float value)
Puts a key/value pair into the array, optimizing for the case where the key is greater than all
existing keys in the array.
|
void |
clear()
Removes all key-value mappings from this SparseFloatArray.
|
SparseFloatArray |
clone() |
int[] |
copyKeys()
Provides a copy of keys.
|
void |
delete(int key)
Removes the mapping from the specified key, if there was any.
|
float |
get(int key)
Gets the float mapped from the specified key, or
0f if no such mapping has been
made. |
float |
get(int key,
float valueIfKeyNotFound)
Gets the float mapped from the specified key, or the specified value if no such mapping has
been made.
|
int |
indexOfKey(int key)
Returns the index for which
keyAt(int) would return the specified key, or a negative number
if the specified key is not mapped. |
int |
indexOfValue(float value)
Returns an index for which
valueAt(int) would return the specified key, or a negative
number if no keys map to the specified value. |
int |
keyAt(int index)
Given an index in the range
0...size()-1 , returns the key from the index
th key-value mapping that this SparseFloatArray stores. |
void |
put(int key,
float value)
Adds a mapping from the specified key to the specified value, replacing the previous mapping
from the specified key if there was one.
|
void |
removeAt(int index)
Removes the mapping at the given index.
|
void |
setValueAt(int index,
float value)
Directly set the value at a particular index.
|
int |
size()
Returns the number of key-value mappings that this SparseFloatArray currently stores.
|
java.lang.String |
toString()
This implementation composes a string by iterating over its mappings.
|
float |
valueAt(int index)
Given an index in the range
0...size()-1 , returns the value from the index
th key-value mapping that this SparseFloatArray stores. |
public SparseFloatArray()
public SparseFloatArray(int initialCapacity)
public SparseFloatArray clone()
clone
in class java.lang.Object
public float get(int key)
0f
if no such mapping has been
made.public float get(int key, float valueIfKeyNotFound)
public void delete(int key)
public void removeAt(int index)
public void put(int key, float value)
public int size()
public int keyAt(int index)
0...size()-1
, returns the key from the index
th key-value mapping that this SparseFloatArray stores.
The keys corresponding to indices in ascending order are guaranteed to be in ascending
order, e.g., keyAt(0)
will return the smallest key and keyAt(size()-1)
will return the largest key.
public float valueAt(int index)
0...size()-1
, returns the value from the index
th key-value mapping that this SparseFloatArray stores.
The values corresponding to indices in ascending order are guaranteed to be associated with
keys in ascending order, e.g., valueAt(0)
will return the value associated with
the smallest key and valueAt(size()-1)
will return the value associated with the
largest key.
public void setValueAt(int index, float value)
public int indexOfKey(int key)
keyAt(int)
would return the specified key, or a negative number
if the specified key is not mapped.public int indexOfValue(float value)
valueAt(int)
would return the specified key, or a negative
number if no keys map to the specified value. Beware that this is a linear search, unlike
lookups by key, and that multiple keys can map to the same value and this will find only one of
them.public void clear()
public void append(int key, float value)
public int[] copyKeys()
public java.lang.String toString()
toString
in class java.lang.Object