Most visited

Recently visited

SimpleArrayMap

public class SimpleArrayMap
extends Object

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


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)

Indicates whether some other object is "equal to" this one.

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

V get(Object key)

Retrieve a value from the array.

int hashCode()

Returns a hash code value for the object.

int indexOfKey(Object key)

Returns the index of a key in the set.

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 representation of the 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.

Inherited methods

From class java.lang.Object

Public constructors

SimpleArrayMap

SimpleArrayMap ()

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

SimpleArrayMap

SimpleArrayMap (int capacity)

Create a new ArrayMap with a given initial capacity.

Parameters
capacity int

SimpleArrayMap

SimpleArrayMap (SimpleArrayMap map)

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

Parameters
map SimpleArrayMap

Public methods

clear

void clear ()

Make the array map empty. All storage is released.

containsKey

boolean containsKey (Object key)

Check whether a key exists in the array.

Parameters
key Object: The key to search for.
Returns
boolean Returns true if the key exists, else false.

containsValue

boolean containsValue (Object value)

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

Parameters
value Object: The value to search for.
Returns
boolean Returns true if the value exists, else false.

ensureCapacity

void ensureCapacity (int minimumCapacity)

Ensure the array map can hold at least minimumCapacity items.

Parameters
minimumCapacity int

equals

boolean equals (Object object)

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.

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.

Parameters
object Object: the reference object with which to compare.
Returns
boolean true if this object is the same as the obj argument; false otherwise.

get

V get (Object key)

Retrieve a value from the array.

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

hashCode

int hashCode ()

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

Returns
int a hash code value for this object.

indexOfKey

int indexOfKey (Object key)

Returns the index of a key in the set.

Parameters
key Object: The key to search for.
Returns
int Returns the index of the key if it exists, else a negative integer.

isEmpty

boolean isEmpty ()

Return true if the array map contains no items.

Returns
boolean

keyAt

K keyAt (int index)

Return the key at the given index in the array.

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

put

V put (K key, 
                V value)

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

putAll

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

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

Parameters
array SimpleArrayMap: The array whose contents are to be retrieved.

remove

V remove (Object key)

Remove an existing key from the array map.

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

removeAt

V removeAt (int index)

Remove the key/value mapping at the given index.

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

setValueAt

V setValueAt (int index, 
                V value)

Set the value at a given index in the array.

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

size

int size ()

Return the number of items in this array map.

Returns
int

toString

String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

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

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
String a string representation of the object.

valueAt

V valueAt (int index)

Return the value at the given index in the array.

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

Hooray!