com.sdm.quasar.client.core.common.util
Class ArrayMap

java.lang.Object
  extended bycom.sdm.quasar.client.core.common.util.BaseArrayMap
      extended bycom.sdm.quasar.client.core.common.util.ArrayMap
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class ArrayMap
extends BaseArrayMap
implements java.lang.Cloneable, java.util.Map

Storage mechanism for key-value pairs. For few pairs this will be an array of alternating key-value pairs. As it grows larger it is scaled up to a HashMap.

Note: Althrough this implementation supports the Map interface, it is not always performant for some Map methods, like the view-sets and collections. Especially the Map entries are not supported fully performant to avoid larger space requirements for small mappings. For large mappings all the map views are taken from the underlying HashMap, so performance should be ok in general.

Author:
Thomas Wolf
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
ArrayMap()
          Constructor for ArrayMap.
 
Method Summary
 void clear()
          Removes all the mappings.
 java.lang.Object clone()
          Clones the ArrayMap.
 boolean containsKey(java.lang.Object key)
          Returns true if we have a value for the key.
 boolean containsValue(java.lang.Object value)
          Returns true if there map one or more keys to the specified value.
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
          Gets the value for key
 boolean isEmpty()
          Returns true if this map contains no key-value mappings.
 java.util.Iterator iterateKeys()
          Returns an iterator of the keys in this BaseArrayMap.
 java.util.Iterator iterateValues()
          Returns an iterator of the values in this BaseArrayMap.
 java.util.Set keySet()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Put the key-value pair into storage
 void putAll(java.util.Map t)
          Copies all of the mappings from the specified map to this map.
 java.lang.Object remove(java.lang.Object key)
          Removes the key and its value Returns the value for the pair removed
 int size()
          Returns the number of pairs in storage
 java.util.Collection values()
           
 
Methods inherited from class com.sdm.quasar.client.core.common.util.BaseArrayMap
copyTo, elementsToString, eq, equals, getKeys, hashCode, iterateMapEntries, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

ArrayMap

public ArrayMap()
Constructor for ArrayMap.

Method Detail

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Put the key-value pair into storage

Specified by:
put in interface java.util.Map
Overrides:
put in class BaseArrayMap
Parameters:
key - the key object
value - the value object
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.

get

public java.lang.Object get(java.lang.Object key)
Gets the value for key

Specified by:
get in interface java.util.Map
Overrides:
get in class BaseArrayMap
Parameters:
key - the key object to look for
Returns:
the associated value

size

public int size()
Returns the number of pairs in storage

Specified by:
size in interface java.util.Map
Overrides:
size in class BaseArrayMap

isEmpty

public boolean isEmpty()
Returns true if this map contains no key-value mappings. This implementation returns size()==0.

Specified by:
isEmpty in interface java.util.Map
Overrides:
isEmpty in class BaseArrayMap

containsKey

public boolean containsKey(java.lang.Object key)
Returns true if we have a value for the key.

Specified by:
containsKey in interface java.util.Map
Overrides:
containsKey in class BaseArrayMap
Returns:
true if we have a value for the key.

containsValue

public boolean containsValue(java.lang.Object value)
Returns true if there map one or more keys to the specified value.

Specified by:
containsValue in interface java.util.Map
Overrides:
containsValue in class BaseArrayMap
Returns:
true if maps one or more keys to the specified value.

remove

public java.lang.Object remove(java.lang.Object key)
Removes the key and its value Returns the value for the pair removed

Specified by:
remove in interface java.util.Map
Overrides:
remove in class BaseArrayMap
Parameters:
key - the key object
Returns:
the associated value object

clear

public void clear()
Removes all the mappings.

Specified by:
clear in interface java.util.Map
Overrides:
clear in class BaseArrayMap

iterateKeys

public java.util.Iterator iterateKeys()
Returns an iterator of the keys in this BaseArrayMap. The general contract for the iterateKeys method is that an Iterator object is returned that will generate all the keys for which this BaseArrayMap contains entries.

Overrides:
iterateKeys in class BaseArrayMap
Returns:
an iterator of the keys in this BaseArrayMap.

iterateValues

public java.util.Iterator iterateValues()
Returns an iterator of the values in this BaseArrayMap. The general contract for the iterateValues method is that an Iterator object is returned that will generate all the values for which this BaseArrayMap contains entries.

Overrides:
iterateValues in class BaseArrayMap
Returns:
an iterator of the values in this BaseArrayMap.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones the ArrayMap. This gives the clone its own copy of the key/value list.

Throws:
java.lang.CloneNotSupportedException

putAll

public void putAll(java.util.Map t)
Copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map.

Specified by:
putAll in interface java.util.Map
Overrides:
putAll in class BaseArrayMap
Parameters:
t - the map to put mappings from

keySet

public java.util.Set keySet()
Specified by:
keySet in interface java.util.Map

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map