-
- All Implemented Interfaces:
-
java.lang.Cloneable
public class SparseArrayCompat<E> implements Cloneable
A copy of the current platform (VERSION_CODES#KITKAT) version of android.util.SparseArray. It provides a removeAt() method and other things.
-
-
Constructor Summary
Constructors Constructor Description SparseArrayCompat()Creates a new SparseArray containing no mappings. SparseArrayCompat(int initialCapacity)Creates a new SparseArray containing no mappings that will notrequire any additional memory allocation to store the specifiednumber of mappings.
-
Method Summary
Modifier and Type Method Description SparseArrayCompat<E>clone()Eget(int key)Gets the Object mapped from the specified key, or nullif no such mapping has been made.Eget(int key, E valueIfKeyNotFound)Gets the Object mapped from the specified key, or the specified Objectif no such mapping has been made. Eremove(int key)Removes the mapping from the specified key, if there was any. voidremoveAt(int index)Removes the mapping at the specified index. voidremoveAtRange(int index, int size)Remove a range of mappings as a batch. voidput(int key, E value)Adds a mapping from the specified key to the specified value,replacing the previous mapping from the specified key if therewas one. intsize()Returns the number of key-value mappings that this SparseArraycurrently stores. intkeyAt(int index)Given an index in the range 0...size()-1, returnsthe key from theindexth key-value mapping that thisSparseArray stores.EvalueAt(int index)Given an index in the range 0...size()-1, returnsthe value from theindexth key-value mapping that thisSparseArray stores.voidsetValueAt(int index, E value)Given an index in the range 0...size()-1, sets a newvalue for theindexth key-value mapping that thisSparseArray stores.intindexOfKey(int key)Returns the index for which keyAt would return thespecified key, or a negative number if the specifiedkey is not mapped. intindexOfValue(E value)Returns an index for which valueAt would return thespecified key, or a negative number if no keys map to thespecified value. voidclear()Removes all key-value mappings from this SparseArray. voidappend(int key, E value)Puts a key/value pair into the array, optimizing for the case wherethe key is greater than all existing keys in the array. StringtoString()This implementation composes a string by iterating over its mappings. -
-
Constructor Detail
-
SparseArrayCompat
SparseArrayCompat()
Creates a new SparseArray containing no mappings.
-
SparseArrayCompat
SparseArrayCompat(int initialCapacity)
Creates a new SparseArray containing no mappings that will notrequire any additional memory allocation to store the specifiednumber of mappings.
-
-
Method Detail
-
clone
SparseArrayCompat<E> clone()
-
get
E get(int key)
Gets the Object mapped from the specified key, or
nullif no such mapping has been made.
-
get
E get(int key, E valueIfKeyNotFound)
Gets the Object mapped from the specified key, or the specified Objectif no such mapping has been made.
-
removeAt
void removeAt(int index)
Removes the mapping at the specified index.
- Parameters:
index- index at which remove item
-
removeAtRange
void removeAtRange(int index, int size)
Remove a range of mappings as a batch.
- Parameters:
index- Index to begin atsize- Number of mappings to remove
-
put
void put(int key, E value)
Adds a mapping from the specified key to the specified value,replacing the previous mapping from the specified key if therewas one.
-
size
int size()
Returns the number of key-value mappings that this SparseArraycurrently stores.
-
keyAt
int keyAt(int index)
Given an index in the range
0...size()-1, returnsthe key from theindexth key-value mapping that thisSparseArray stores.
-
valueAt
E valueAt(int index)
Given an index in the range
0...size()-1, returnsthe value from theindexth key-value mapping that thisSparseArray stores.
-
setValueAt
void setValueAt(int index, E value)
Given an index in the range
0...size()-1, sets a newvalue for theindexth key-value mapping that thisSparseArray stores.
-
indexOfKey
int indexOfKey(int key)
Returns the index for which keyAt would return thespecified key, or a negative number if the specifiedkey is not mapped.
-
indexOfValue
int indexOfValue(E value)
Returns an index for which valueAt would return thespecified key, or a negative number if no keys map to thespecified value.
Beware that this is a linear search, unlike lookups by key,and that multiple keys can map to the same value and this willfind only one of them.
Note also that unlike most collections'
{@code indexOf}methods,this method compares values using{@code ==}rather than{@code equals}.
-
clear
void clear()
Removes all key-value mappings from this SparseArray.
-
append
void append(int key, E value)
Puts a key/value pair into the array, optimizing for the case wherethe key is greater than all existing keys in the array.
-
-
-
-