Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public class

SimpleArrayMap

extends Object
java.lang.Object
   ↳ android.support.v4.util.SimpleArrayMap<K, V>
Known Direct Subclasses

Class Overview

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
SimpleArrayMap ()
Create a new empty ArrayMap.
SimpleArrayMap (int capacity)
Create a new ArrayMap with a given initial capacity.
SimpleArrayMap ( SimpleArrayMap map)
Create a new ArrayMap with the mappings from the given ArrayMap.
Public Methods
void clear ()
Make the array map empty.
boolean containsKey ( Object key)
Check whether a key exists in the array.
boolean containsValue ( Object value)
Check whether a value exists in the array.
void ensureCapacity (int minimumCapacity)
Ensure the array map can hold at least minimumCapacity items.
boolean equals ( Object object)
Compares this instance with the specified object and indicates if they are equal.

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

V get ( Object key)
Retrieve a value from the array.
int hashCode ()
Returns an integer hash code for this object.
boolean isEmpty ()
Return true if the array map contains no items.
K keyAt (int index)
Return the key at the given index in the array.
V put (K key, V value)
Add a new value to the array map.
void )">putAll ( SimpleArrayMap <? extends K, ? extends V> array)
Perform a put(Object, Object) of all key/value pairs in array
V remove ( Object key)
Remove an existing key from the array map.
V removeAt (int index)
Remove the key/value mapping at the given index.
V setValueAt (int index, V value)
Set the value at a given index in the array.
int size ()
Return the number of items in this array map.
String toString ()
Returns a string containing a concise, human-readable description of this object.

This implementation composes a string by iterating over its mappings.

V valueAt (int index)
Return the value at the given index in the array.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public SimpleArrayMap ()

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

public SimpleArrayMap (int capacity)

Create a new ArrayMap with a given initial capacity.

public SimpleArrayMap ( SimpleArrayMap map)

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

Public Methods

public void clear ()

Make the array map empty. All storage is released.

public boolean containsKey ( Object key)

Check whether a key exists in the array.

Parameters
key The key to search for.
Returns
  • Returns true if the key exists, else false.

public boolean containsValue ( Object value)

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

Parameters
value The value to search for.
Returns
  • Returns true if the value exists, else false.

public void ensureCapacity (int minimumCapacity)

Ensure the array map can hold at least minimumCapacity items.

public boolean equals ( Object object)

Compares this instance with the specified object and indicates if they are equal. In order to be equal, o must represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be reflexive, symmetric, and transitive. Also, no object reference other than null is equal to null.

The default implementation returns true only if this == o . See Writing a correct equals method if you intend implementing your own equals method.

The general contract for the equals and hashCode() methods is that if equals returns true for any two objects, then hashCode() must return the same value for these objects. This means that subclasses of Object usually override either both methods or neither of them.

This implementation returns false if the object is not a map, 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.

Parameters
object the object to compare this instance with.
Returns
  • true if the specified object is equal to this Object ; false otherwise.

public V get ( Object key)

Retrieve a value from the array.

Parameters
key The key of the value to retrieve.
Returns
  • Returns the value associated with the given key, or null if there is no such key.

public int hashCode ()

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
  • this object's hash code.

public boolean isEmpty ()

Return true if the array map contains no items.

public K keyAt (int index)

Return the key at the given index in the array.

Parameters
index The desired index, must be between 0 and size() -1.
Returns
  • Returns the key stored at the given index.

public V put (K key, V value)

Add a new value to the array map.

Parameters
key 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 The value to store for the given key.
Returns
  • Returns the old value that was stored for the given key, or null if there was no such key.
)">

public void putAll ( SimpleArrayMap <? extends K, ? extends V> array)

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

Parameters
array The array whose contents are to be retrieved.

public V remove ( Object key)

Remove an existing key from the array map.

Parameters
key The key of the mapping to remove.
Returns
  • Returns the value that was stored under the key, or null if there was no such key.

public V removeAt (int index)

Remove the key/value mapping at the given index.

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

public V setValueAt (int index, V value)

Set the value at a given index in the array.

Parameters
index The desired index, must be between 0 and size() -1.
value The new value to store at this index.
Returns
  • Returns the previous value at the given index.

public int size ()

Return the number of items in this array map.

public String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

          getClass().getName() + '@' + Integer.toHexString(hashCode())
         

See Writing a useful toString method if you intend implementing your own toString method.

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.

Returns
  • a printable representation of this object.

public V valueAt (int index)

Return the value at the given index in the array.

Parameters
index The desired index, must be between 0 and size() -1.
Returns
  • Returns the value stored at the given index.