SimpleArrayMap
-
Cmn
open class SimpleArrayMap<K : Any?, V : Any?>
ArrayMap |
ArrayMap is a generic key->value mapping data structure that is designed to be more memory efficient than a traditional |
Base implementation of androidx.collection.ArrayMap that doesn't include any standard Java container API interoperability. These features are generally heavier-weight ways to interact with the container, so discouraged, but they can be useful to make it easier to use as a drop-in replacement for HashMap. If you don't need them, this class can be preferable since it doesn't bring in any of the implementation of those APIs, allowing that code to be stripped by ProGuard.
NOTE: Consider using MutableScatterMap
instead of this class. MutableScatterMap
also avoids creating a new object per entry but offers better performance characteristics. If a Map
interface is required, see MutableScatterMap.asMap
. If a MutableMap
interface is required, see MutableScatterMap.asMutableMap
. A MutableScatterMap
can also be passed as a ScatterMap
to provide a read-only API surface.
Summary
Public constructors |
|
---|---|
<K : Any?, V : Any?> SimpleArrayMap(capacity: Int) Create a new |
Cmn
|
<K : Any?, V : Any?> SimpleArrayMap(map: SimpleArrayMap<K, V>?) Create a new |
Cmn
|
Public functions |
||
---|---|---|
open Unit |
clear() Make the array map empty. |
Cmn
|
open Boolean |
containsKey(key: K) Check whether a key exists in the array. |
Cmn
|
open Boolean |
containsValue(value: V) Check whether a value exists in the array. |
Cmn
|
open Unit |
ensureCapacity(minimumCapacity: Int) Ensure the array map can hold at least |
Cmn
|
open operator Boolean |
This implementation returns |
Cmn
|
open operator V? |
get(key: K) Retrieve a value from the array. |
Cmn
|
open V |
getOrDefault(key: Any?, defaultValue: V) Retrieve a value from the array, or |
Cmn
|
open Int |
hashCode() |
Cmn
|
open Int |
indexOfKey(key: K) Returns the index of a key in the set. |
Cmn
|
open Boolean |
isEmpty() Return |
Cmn
|
open K |
Return the key at the given index in the array. |
Cmn
|
open V? |
put(key: K, value: V) Add a new value to the array map. |
Cmn
|
open Unit |
putAll(map: SimpleArrayMap<K, V>) |
Cmn
|
open V? |
putIfAbsent(key: K, value: V) Add a new value to the array map only if the key does not already have a value or it is mapped to |
Cmn
|
open V? |
remove(key: K) Remove an existing key from the array map. |
Cmn
|
open Boolean |
remove(key: K, value: V) Remove an existing key from the array map only if it is currently mapped to |
Cmn
|
open V |
Remove the key/value mapping at the given index. |
Cmn
|
open V? |
replace(key: K, value: V) Replace the mapping for |
Cmn
|
open Boolean |
replace(key: K, oldValue: V, newValue: V) Replace the mapping for |
Cmn
|
open V |
setValueAt(index: Int, value: V) Set the value at a given index in the array. |
Cmn
|
open Int |
size() Return the number of items in this array map. |
Cmn
|
open String |
toString() Returns a string representation of the object. |
Cmn
|
open V |
Return the value at the given index in the array. |
Cmn
|
Public constructors
SimpleArrayMap
<K : Any?, V : Any?> SimpleArrayMap(capacity: Int = 0)
Create a new SimpleArrayMap
with a given initial capacity. The default capacity of an array map is 0, and will grow once items are added to it.
SimpleArrayMap
<K : Any?, V : Any?> SimpleArrayMap(map: SimpleArrayMap<K, V>?)
Create a new SimpleArrayMap
with the mappings from the given map
.
Public functions
clear
open fun clear(): Unit
Make the array map empty. All storage is released.
Throws | |
---|---|
kotlin.ConcurrentModificationException |
if it was detected that this |
containsKey
open fun containsKey(key: K): Boolean
Check whether a key exists in the array.
Parameters | |
---|---|
key: K |
The key to search for. |
Returns | |
---|---|
Boolean |
Returns |
containsValue
open fun containsValue(value: V): Boolean
Check whether a value exists in the array. This requires a linear search through the entire array.
Parameters | |
---|---|
value: V |
The value to search for. |
Returns | |
---|---|
Boolean |
Returns |
ensureCapacity
open fun ensureCapacity(minimumCapacity: Int): Unit
Ensure the array map can hold at least minimumCapacity
items.
Throws | |
---|---|
kotlin.ConcurrentModificationException |
if it was detected that this |
equals
open operator fun equals(other: Any?): Boolean
This implementation returns false
if the object is not a Map
or SimpleArrayMap
, or if the maps have different sizes. Otherwise, for each key in this map, values of both maps are compared. If the values for any key are not equal, the method returns false, otherwise it returns true
.
get
open operator fun get(key: K): V?
Retrieve a value from the array.
Parameters | |
---|---|
key: K |
The key of the value to retrieve. |
Returns | |
---|---|
V? |
Returns the value associated with the given key, or |
getOrDefault
open fun getOrDefault(key: Any?, defaultValue: V): V
Retrieve a value from the array, or defaultValue
if there is no mapping for the key.
Parameters | |
---|---|
key: Any? |
The key of the value to retrieve. |
defaultValue: V |
The default mapping of the key |
Returns | |
---|---|
V |
Returns the value associated with the given key, or |
indexOfKey
open fun indexOfKey(key: K): Int
Returns the index of a key in the set.
Parameters | |
---|---|
key: K |
The key to search for. |
Returns | |
---|---|
Int |
Returns the index of the key if it exists, else a negative integer. |
keyAt
open fun keyAt(index: Int): K
Return the key at the given index in the array.
Returns | |
---|---|
K |
Returns the key stored at the given index. |
put
open fun put(key: K, value: V): V?
Add a new value to the array map.
Parameters | |
---|---|
key: K |
The key under which to store the value. If this key already exists in the array, its value will be replaced. |
value: V |
The value to store for the given key. |
Returns | |
---|---|
V? |
Returns the old value that was stored for the given key, or |
Throws | |
---|---|
kotlin.ConcurrentModificationException |
if it was detected that this |
putAll
open fun putAll(map: SimpleArrayMap<K, V>): Unit
Perform a put
of all key/value pairs in map
Parameters | |
---|---|
map: SimpleArrayMap<K, V> |
The array whose contents are to be retrieved. |
putIfAbsent
open fun putIfAbsent(key: K, value: V): V?
Add a new value to the array map only if the key does not already have a value or it is mapped to null
.
Parameters | |
---|---|
key: K |
The key under which to store the value. |
value: V |
The value to store for the given key. |
Returns | |
---|---|
V? |
Returns the value that was stored for the given key, or |
remove
open fun remove(key: K): V?
Remove an existing key from the array map.
Parameters | |
---|---|
key: K |
The key of the mapping to remove. |
Returns | |
---|---|
V? |
Returns the value that was stored under the key, or |
remove
open fun remove(key: K, value: V): Boolean
Remove an existing key from the array map only if it is currently mapped to value
.
Parameters | |
---|---|
key: K |
The key of the mapping to remove. |
value: V |
The value expected to be mapped to the key. |
Returns | |
---|---|
Boolean |
Returns |
removeAt
open fun removeAt(index: Int): V
Remove the key/value mapping at the given index.
Returns | |
---|---|
V |
Returns the value that was stored at this index. |
Throws | |
---|---|
kotlin.ConcurrentModificationException |
if it was detected that this |
kotlin.IllegalArgumentException |
replace
open fun replace(key: K, value: V): V?
Replace the mapping for key
only if it is already mapped to a value.
Parameters | |
---|---|
key: K |
The key of the mapping to replace. |
value: V |
The value to store for the given key. |
Returns | |
---|---|
V? |
Returns the previous mapped value or |
replace
open fun replace(key: K, oldValue: V, newValue: V): Boolean
Replace the mapping for key
only if it is already mapped to oldValue
.
Parameters | |
---|---|
key: K |
The key of the mapping to replace. |
oldValue: V |
The value expected to be mapped to the key. |
newValue: V |
The value to store for the given key. |
Returns | |
---|---|
Boolean |
Returns |
setValueAt
open fun setValueAt(index: Int, value: V): V
Set the value at a given index in the array.
Parameters | |
---|---|
index: Int |
The desired index, must be between 0 and |
value: V |
The new value to store at this index. |
Returns | |
---|---|
V |
Returns the previous value at the given index. |
toString
open fun toString(): String
Returns a string representation of the object.
This implementation composes a string by iterating over its mappings. If this map contains itself as a key or a value, the string "(this Map)" will appear in its place.
valueAt
open fun valueAt(index: Int): V
Return the value at the given index in the array.
Returns | |
---|---|
V |
Returns the value stored at the given index. |