Nitido Inc.

com.nitido.util
Class OpenHashMap<K,V>

java.lang.Object
  extended by com.nitido.util.OpenHashMap<K,V>
All Implemented Interfaces:
java.io.Serializable, java.util.Map<K,V>

public class OpenHashMap<K,V>
extends java.lang.Object
implements java.io.Serializable, java.util.Map<K,V>

A HashMap that allows more than one value associated to the same key. This object is replacing the com.nitido.util.OpenHash. It performs much better than the old OpenHash object because none of its methods are synchronized.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
OpenHashMap()
          Constructs a new, empty OpenHashMap.
OpenHashMap(java.util.Map<? extends K,? extends V> hash)
          Constructs a new OpenHashMap, copying the contents of the passed in HashMap object into the OpenHashMap.
OpenHashMap(OpenHashMap<? extends K,? extends V> hash)
          Copy constructor.
 
Method Summary
 void clear()
          This method removes all entries from the hashMap.
 boolean containsKey(java.lang.Object key)
          Returns true if this OpenHashMap contains a key equal to the one passed in.
 boolean containsValue(K key, V value)
          Returns true if this OpenHashMap contains the given value with the given key.
 boolean containsValue(java.lang.Object value)
          Returns true if this OpenHashMap contains the given value.
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
          Required by java.util.Map.
 V get(java.lang.Object key)
          This method retrieves the first value which corresponds to the key given, or null if no value is mapped to that key.
 V get(java.lang.Object key, int index)
          This method retrieves the specified value which corresponds to the key given and the specified index, or null if no value is mapped to that key.
 int getNumberOfValues(java.lang.Object key)
          Returns number of value object stored under the specified key.
 V getValue(java.lang.Object key, int index)
          Return the value specified by the index.
 java.util.List<V> getValues(java.lang.Object key)
          Returns a arrayList of all the values associated to the given key.
 boolean isEmpty()
          Required by java.util.Map.
 java.util.Set<K> keySet()
          Convenience alias to getKeys() for HashMap users.
 V put(K key, V value)
          This method maps a key to a value in the hashMap.
 void putAll(java.util.Map<? extends K,? extends V> inMap)
          Required by java.util.Map.
 void putValues(K key, java.util.Collection<? extends V> values)
          This method maps a key to a value in the hashMap.
 V remove(K key, int index)
          Remove the specified value associated to the key.
 V remove(K key, V value)
          Removes the key/value pair specified.
 V remove(java.lang.Object key)
          Removes all the values that are associated with the given key.
 void set(K key, int index, V value)
          This method replace the specified value with the new value.
 void set(K key, V value)
          This method maps a key to a value in the hashMap and replace the all old mapped values if they exist.
 void setValues(K key, java.util.Collection<? extends V> values)
          This method replace all old mapped values with the new ones.
 int size()
          Returns the number of keys in this OpenHashMap.
 java.lang.String toString()
          Utility methods to list all the entries in the hashMap.
 java.util.Collection<V> values()
          Required by java.util.Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

OpenHashMap

public OpenHashMap()
Constructs a new, empty OpenHashMap.


OpenHashMap

public OpenHashMap(java.util.Map<? extends K,? extends V> hash)
Constructs a new OpenHashMap, copying the contents of the passed in HashMap object into the OpenHashMap.

Parameters:
hash - The HashMap whose contents are copied into this OpenHashMap.

OpenHashMap

public OpenHashMap(OpenHashMap<? extends K,? extends V> hash)
Copy constructor.

Method Detail

get

public V get(java.lang.Object key)
This method retrieves the first value which corresponds to the key given, or null if no value is mapped to that key.

Specified by:
get in interface java.util.Map<K,V>
Parameters:
key - A key in the hashMap.
Returns:
The first mapping or null if there is none.

get

public V get(java.lang.Object key,
             int index)
This method retrieves the specified value which corresponds to the key given and the specified index, or null if no value is mapped to that key.

Parameters:
key - A key in the hashMap.
Returns:
The first mapping or null if there is none.

keySet

public java.util.Set<K> keySet()
Convenience alias to getKeys() for HashMap users.

Specified by:
keySet in interface java.util.Map<K,V>

getNumberOfValues

public int getNumberOfValues(java.lang.Object key)
Returns number of value object stored under the specified key.

Parameters:
key - The key object to retrieve the value count from.
Returns:
The count of the values stored under the key.

getValues

public java.util.List<V> getValues(java.lang.Object key)
Returns a arrayList of all the values associated to the given key.

Parameters:
key - A key in the hashMap.
Returns:
A arrayList of the values associated too the key

getValue

public V getValue(java.lang.Object key,
                  int index)
Return the value specified by the index.

Parameters:
key - A key in the hashMap.
index - The index of the value to be fetched.
Returns:
The specified value.

containsValue

public boolean containsValue(java.lang.Object value)
Returns true if this OpenHashMap contains the given value.

Specified by:
containsValue in interface java.util.Map<K,V>
Parameters:
value - The value to check for in this OpenHashMap.
Returns:
True if the value is found in the OpenHashMap, otherwise false.

containsValue

public boolean containsValue(K key,
                             V value)
Returns true if this OpenHashMap contains the given value with the given key.

Parameters:
key - The key to search for in this OpenHashMap.
value - The value to search for in this OpenHashMap.
Returns:
Returns true if the key/value pair is found, otherwise returns false.

containsKey

public boolean containsKey(java.lang.Object key)
Returns true if this OpenHashMap contains a key equal to the one passed in.

Specified by:
containsKey in interface java.util.Map<K,V>
Parameters:
key - The key to check.
Returns:
True if the key is found, false otherwise.

size

public int size()
Returns the number of keys in this OpenHashMap.

Specified by:
size in interface java.util.Map<K,V>
Returns:
The number of keys in this OpenHashMap.

put

public V put(K key,
             V value)
This method maps a key to a value in the hashMap.

Specified by:
put in interface java.util.Map<K,V>
Parameters:
key - The object to be used as a key in the mapping.
value - The object which the key is being mapped to.
Returns:
always null. It is because this OpenHashMap allows more than one value associated to a specific key. Unlike the regular Map interface, this implementation will never replace the previous value in the map. Therefore, it will always return null.

putValues

public void putValues(K key,
                      java.util.Collection<? extends V> values)
This method maps a key to a value in the hashMap. It will add the new values to the existing values associated to the key.

Parameters:
key - The object to be used as a key in the mapping.
values - The collection of the values associated to the key.

set

public void set(K key,
                V value)
This method maps a key to a value in the hashMap and replace the all old mapped values if they exist.

Parameters:
key - The object to be used as a key in the mapping.
value - The object which the key is being mapped to.

setValues

public void setValues(K key,
                      java.util.Collection<? extends V> values)
This method replace all old mapped values with the new ones.

Parameters:
key - The object to be used as a key in the mapping.
values - The collection of values to be associated to the key.

set

public void set(K key,
                int index,
                V value)
This method replace the specified value with the new value. It will only replace the value pointed by the index, and all other values remains unchanged.

Parameters:
key - The object to be used as a key in the mapping.
index - The index of the value to be replaced.
value - The object which the key is being mapped to.

remove

public V remove(java.lang.Object key)
Removes all the values that are associated with the given key.

Specified by:
remove in interface java.util.Map<K,V>
Parameters:
key - the key to be removed.
Returns:
the first value associated to the key. It will return null if the key was not set before.

remove

public V remove(K key,
                V value)
Removes the key/value pair specified.

Parameters:
key - The key in the key/value pair to remove.
value - The value in the key/value pair to remove.
Returns:
The element removed, or null if no matching key/value pair was found.

remove

public V remove(K key,
                int index)
Remove the specified value associated to the key. If the specified index doesn't exists, this method will not change anything under the key and return a null object. If there exists a value under the specified key and index, that value will be removed from the hash and returned by this method.

Parameters:
key - The key in the key/value pair to be removed.
index - The index of the value to be removed.

clear

public void clear()
This method removes all entries from the hashMap.

Specified by:
clear in interface java.util.Map<K,V>

toString

public java.lang.String toString()
Utility methods to list all the entries in the hashMap. The format will be
 keyA: "valueA-1", "valueA-2", ...
 keyB: "valueB-1", "valueB-2", ...
 

Overrides:
toString in class java.lang.Object

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Required by java.util.Map. This method always throw exception. It is because OpenHashMap is a one-to-many map and should not return a set of one-to-one map entries.

Specified by:
entrySet in interface java.util.Map<K,V>

putAll

public void putAll(java.util.Map<? extends K,? extends V> inMap)
Required by java.util.Map.

Specified by:
putAll in interface java.util.Map<K,V>

values

public java.util.Collection<V> values()
Required by java.util.Map. Return all values of the OpenHashMap. This set may contains duplicated values and does not guarantee the order of the values.

Specified by:
values in interface java.util.Map<K,V>

isEmpty

public boolean isEmpty()
Required by java.util.Map. Return true if there is no key has been defined.

Specified by:
isEmpty in interface java.util.Map<K,V>

Nitido NiM 2.5 Java API

These JavaDoc pages are generated for release/nim_2_5-2.5.44

Copyright © 1999-2009 Nitido Inc.    Proprietary and Confidential.    All Rights Reserved.