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

java.lang.Object
  extended bycom.sdm.quasar.client.core.common.util.BaseArrayMap
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ArrayMap

public class BaseArrayMap
extends java.lang.Object
implements java.io.Serializable

A protected implementation of a simple storing 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. Subclasses may overwrite methods to enable public access.

Author:
Thomas Wolf
See Also:
Serialized Form

Constructor Summary
protected BaseArrayMap()
          Creates a new BaseArrayMap.
 
Method Summary
protected  void clear()
          Removes all the mappings.
protected  boolean containsKey(java.lang.Object key)
          Returns true if we have a value for the key.
protected  boolean containsValue(java.lang.Object value)
          Returns true if there map one or more keys to the specified value.
protected  BaseArrayMap copyTo(BaseArrayMap arraymap)
          Copies the contents to the given BaseArrayMap.
 java.lang.String elementsToString(java.lang.String key_value_separator, java.lang.String pair_separator)
          Returns a string representation of the key-value pairs.
protected static boolean eq(java.lang.Object o1, java.lang.Object o2)
           
 boolean equals(java.lang.Object obj)
           
protected  java.lang.Object get(java.lang.Object key)
          Gets the value for key
protected  java.lang.Object[] getKeys(java.lang.Object[] keys)
          Returns the keys of the table, or null if there are currently no bindings.
 int hashCode()
           
protected  boolean isEmpty()
          Returns true if this map contains no key-value mappings.
protected  java.util.Iterator iterateKeys()
          Returns an iterator of the keys in this BaseArrayMap.
protected  java.util.Iterator iterateMapEntries()
          Returns an iterator of the Map.Entry in this BaseArrayMap.
protected  java.util.Iterator iterateValues()
          Returns an iterator of the values in this BaseArrayMap.
protected  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.
protected  java.lang.Object remove(java.lang.Object key)
          Removes the key and its value Returns the value for the pair removed
protected  int size()
          Returns the number of pairs in storage
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BaseArrayMap

protected BaseArrayMap()
Creates a new BaseArrayMap.

Method Detail

clear

protected void clear()
Removes all the mappings.


containsKey

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

Returns:
true if we have a value for the key.

containsValue

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

Returns:
true if maps one or more keys to the specified value.

copyTo

protected BaseArrayMap copyTo(BaseArrayMap arraymap)
Copies the contents to the given BaseArrayMap.

Parameters:
arraymap - the BaseArrayMap to copy to

get

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

Parameters:
key - the key object to look for
Returns:
the associated value

getKeys

protected java.lang.Object[] getKeys(java.lang.Object[] keys)
Returns the keys of the table, or null if there are currently no bindings.

Parameters:
keys - array of keys
Returns:
an array of bindings

iterateKeys

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

Returns:
an iterator of the keys in this BaseArrayMap.

iterateValues

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

Returns:
an iterator of the values in this BaseArrayMap.

iterateMapEntries

protected java.util.Iterator iterateMapEntries()
Returns an iterator of the Map.Entry in this BaseArrayMap. Because BaseArrayMap is not based upon AbstractMap to avoid higher space consumption, this iterator has to create every Map.Entry to enable Map compatibility. If the BaseArrayMap is grown to a real map, this returns the entries of the real map. Avoid calling this method in preformance-relevant scenarios!

Returns:
an iterator of the Map.Entry in this BaseArrayMap.

put

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

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.

remove

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

Parameters:
key - the key object
Returns:
the associated value object

size

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


isEmpty

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


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.

Parameters:
t - the map to put mappings from

hashCode

public int hashCode()

equals

public boolean equals(java.lang.Object obj)

toString

public java.lang.String toString()

elementsToString

public java.lang.String elementsToString(java.lang.String key_value_separator,
                                         java.lang.String pair_separator)
Returns a string representation of the key-value pairs.

Parameters:
key_value_separator - the separator string to separate key from value
pair_separator - a separator string to separate key-value pairs

eq

protected static final boolean eq(java.lang.Object o1,
                                  java.lang.Object o2)