|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectandroid.support.v4.util.SimpleArrayMap<K,V>
android.support.v4.util.ArrayMap<K,V>
public class ArrayMap<K,V>
ArrayMap is a generic key->value mapping data structure that is
designed to be more memory efficient than a traditional HashMap
,
this implementation is a version of the platform's
android.util.ArrayMap
that can be used on older versions of the platform.
It keeps its mappings in an array data structure -- an integer array of hash
codes for each item, and an Object array of the key/value pairs. This allows it to
avoid having to create an extra object for every entry put in to the map, and it
also tries to control the growth of the size of these arrays more aggressively
(since growing them only requires copying the entries in the array, not rebuilding
a hash map).
If you don't need the standard Java container APIs provided here (iterators etc),
consider using SimpleArrayMap
instead.
Note that this implementation is not intended to be appropriate for data structures that may contain large numbers of items. It is generally slower than a traditional HashMap, since lookups require a binary search and adds and removes require inserting and deleting entries in the array. For containers holding up to hundreds of items, the performance difference is not significant, less than 50%.
Because this container is intended to better balance memory use, unlike most other standard Java containers it will shrink its array as items are removed from it. Currently you have no control over this shrinking -- if you set a capacity and then remove an item, it may reduce the capacity to better match the current size. In the future an explicit call to set the capacity should turn off this aggressive shrinking behavior.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Constructor Summary | |
---|---|
ArrayMap()
|
|
ArrayMap(int capacity)
Create a new ArrayMap with a given initial capacity. |
|
ArrayMap(SimpleArrayMap map)
Create a new ArrayMap with the mappings from the given ArrayMap. |
Method Summary | |
---|---|
boolean |
containsAll(java.util.Collection<?> collection)
Determine if the array map contains all of the keys in the given collection. |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
Return a Set for iterating over and interacting with all mappings
in the array map. |
java.util.Set<K> |
keySet()
Return a Set for iterating over and interacting with all keys
in the array map. |
void |
putAll(java.util.Map<? extends K,? extends V> map)
Perform a SimpleArrayMap.put(Object, Object) of all key/value pairs in map |
boolean |
removeAll(java.util.Collection<?> collection)
Remove all keys in the array map that exist in the given collection. |
boolean |
retainAll(java.util.Collection<?> collection)
Remove all keys in the array map that do not exist in the given collection. |
java.util.Collection<V> |
values()
Return a Collection for iterating over and interacting with all values
in the array map. |
Methods inherited from class android.support.v4.util.SimpleArrayMap |
---|
clear, containsKey, containsValue, ensureCapacity, equals, get, hashCode, isEmpty, keyAt, put, putAll, remove, removeAt, setValueAt, size, toString, valueAt |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, put, remove, size |
Constructor Detail |
---|
public ArrayMap()
public ArrayMap(int capacity)
public ArrayMap(SimpleArrayMap map)
Method Detail |
---|
public boolean containsAll(java.util.Collection<?> collection)
collection
- The collection whose contents are to be checked against.
public void putAll(java.util.Map<? extends K,? extends V> map)
SimpleArrayMap.put(Object, Object)
of all key/value pairs in map
putAll
in interface java.util.Map<K,V>
map
- The map whose contents are to be retrieved.public boolean removeAll(java.util.Collection<?> collection)
collection
- The collection whose contents are to be used to remove keys.
public boolean retainAll(java.util.Collection<?> collection)
collection
- The collection whose contents are to be used to determine which
keys to keep.
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Set
for iterating over and interacting with all mappings
in the array map.
Note: this is a very inefficient way to access the array contents, it requires generating a number of temporary objects.
Note:
the semantics of this Set are subtly different than that of aHashMap
: most important,
the Map.Entry
object returned by its iterator is a single
object that exists for the entire iterator, so you can not hold on to it
after calling Iterator.next
.
entrySet
in interface java.util.Map<K,V>
public java.util.Set<K> keySet()
Set
for iterating over and interacting with all keys
in the array map.
Note: this is a fairly inefficient way to access the array contents, it requires generating a number of temporary objects.
keySet
in interface java.util.Map<K,V>
public java.util.Collection<V> values()
Collection
for iterating over and interacting with all values
in the array map.
Note: this is a fairly inefficient way to access the array contents, it requires generating a number of temporary objects.
values
in interface java.util.Map<K,V>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |