SimpleArrayMap

open class SimpleArrayMap<K : Any!, V : Any!>
kotlin.Any
   ↳ androidx.collection.SimpleArrayMap

Base implementation of 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 preferrable since it doesn't bring in any of the implementation of those APIs, allowing that code to be stripped by ProGuard.

Summary

Public constructors

Create a new empty ArrayMap.

<init>(capacity: Int)

Create a new ArrayMap with a given initial capacity.

<init>(map: SimpleArrayMap<K, V>!)

Create a new ArrayMap with the mappings from the given ArrayMap.

Public methods
open Int

open Unit

Make the array map empty.

open Int
indexOfKey(key: Any!)

Returns the index of a key in the set.

open V
put(key: K, value: V)

Add a new value to the array map.

open Boolean
equals(other: Any?)

This implementation returns false if the object is not a Map or SimpleArrayMap, or if the maps have different sizes.

open Boolean
containsValue(value: Any!)

Check whether a value exists in the array.

open Boolean

Return true if the array map contains no items.

open V
removeAt(index: Int)

Remove the key/value mapping at the given index.

open String

This implementation composes a string by iterating over its mappings.

open V
remove(key: Any!)

Remove an existing key from the array map.

open Unit
putAll(array: SimpleArrayMap<out K, out V>!)

Perform a #put(Object, Object) of all key/value pairs in array

open V
valueAt(index: Int)

Return the value at the given index in the array.

open Unit
ensureCapacity(minimumCapacity: Int)

Ensure the array map can hold at least minimumCapacity items.

open K
keyAt(index: Int)

Return the key at the given index in the array.

open Int

Return the number of items in this array map.

open Boolean

Check whether a key exists in the array.

open V
get(key: Any!)

Retrieve a value from the array.

open V
setValueAt(index: Int, value: V)

Set the value at a given index in the array.

Public constructors

<init>

SimpleArrayMap()

Create a new empty ArrayMap. The default capacity of an array map is 0, and will grow once items are added to it.

<init>

SimpleArrayMap(capacity: Int)

Create a new ArrayMap with a given initial capacity.

<init>

SimpleArrayMap(map: SimpleArrayMap<K, V>!)

Create a new ArrayMap with the mappings from the given ArrayMap.

Public methods

hashCode

open fun hashCode(): Int

clear

open fun clear(): Unit

Make the array map empty. All storage is released.

indexOfKey

open fun indexOfKey(key: Any!): Int

Returns the index of a key in the set.

Parameters
key Any!: The key to search for.
Return
Int: Returns the index of the key if it exists, else a negative integer.

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. Must not be null. If this key already exists in the array, its value will be replaced.
value K: The value to store for the given key.
Return
V: Returns the old value that was stored for the given key, or null if there was no such key.

equals

open 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.

containsValue

open fun containsValue(value: Any!): Boolean

Check whether a value exists in the array. This requires a linear search through the entire array.

Parameters
value Any!: The value to search for.
Return
Boolean: Returns true if the value exists, else false.

isEmpty

open fun isEmpty(): Boolean

Return true if the array map contains no items.

removeAt

open fun removeAt(index: Int): V

Remove the key/value mapping at the given index.

Parameters
index Int: The desired index, must be between 0 and #size()-1.
Return
V: Returns the value that was stored at this index.

toString

open fun toString(): String

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.

remove

open fun remove(key: Any!): V

Remove an existing key from the array map.

Parameters
key Any!: The key of the mapping to remove.
Return
V: Returns the value that was stored under the key, or null if there was no such key.

putAll

open fun putAll(array: SimpleArrayMap<out K, out V>!): Unit

Perform a #put(Object, Object) of all key/value pairs in array

Parameters
array SimpleArrayMap<out K, out V>!: The array whose contents are to be retrieved.

valueAt

open fun valueAt(index: Int): V

Return the value at the given index in the array.

Parameters
index Int: The desired index, must be between 0 and #size()-1.
Return
V: Returns the value stored at the given index.

ensureCapacity

open fun ensureCapacity(minimumCapacity: Int): Unit

Ensure the array map can hold at least minimumCapacity items.

keyAt

open fun keyAt(index: Int): K

Return the key at the given index in the array.

Parameters
index Int: The desired index, must be between 0 and #size()-1.
Return
K: Returns the key stored at the given index.

size

open fun size(): Int

Return the number of items in this array map.

containsKey

open fun containsKey(key: Any!): Boolean

Check whether a key exists in the array.

Parameters
key Any!: The key to search for.
Return
Boolean: Returns true if the key exists, else false.

get

open fun get(key: Any!): V

Retrieve a value from the array.

Parameters
key Any!: The key of the value to retrieve.
Return
V: Returns the value associated with the given key, or null if there is no such key.

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 #size()-1.
value Int: The new value to store at this index.
Return
V: Returns the previous value at the given index.