org.equanda.util.collection
Class OneToOneHashMap<K,V>

java.lang.Object
  extended by org.equanda.util.collection.OneToOneHashMap<K,V>

public class OneToOneHashMap<K,V>
extends Object

This class provides a mapping between keys and values, but unlike a regular java.util.Map there are two specificities:

The OneToOneHasMap does not allow null keys and it does not allow null values either.

The OneToOneHashMap is unsynchronized. It is intended to used as a "cache": once initialised, it will only be read and there are supposed to be no more modifications. That's the reason why we have not provided a remove method. Of course, this choice can still be switched later on. This class can even be extended to implement java.util.Map, but I'm not sure at the moment whether or not this would be a good idea. We'll have to see once we would re-use this class in other parts of the system.

Author:
Geert Mergan

Constructor Summary
OneToOneHashMap()
           
 
Method Summary
 K getKeyForValue(V value)
          Gets the key that is associated with the given value.
 V getValueForKey(K key)
          Gets the value that is associated with the given key.
 V put(K key, V value)
          Associates the specified value with the specified key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OneToOneHashMap

public OneToOneHashMap()
Method Detail

put

public V put(K key,
             V value)
Associates the specified value with the specified key. The method throws an IllegalArgumentException if the key or the value already exists. It throws a NullPointerException if key or value is null.

Parameters:
key - key
value - value
Returns:
always returns null. The return value is just there to have the same behaviour as the put method in the Map interface.
Throws:
IllegalArgumentException - if there is a previous mapping for the key or the value
NullPointerException - if the key or the value is null

getValueForKey

public V getValueForKey(K key)
Gets the value that is associated with the given key.

Parameters:
key - key
Returns:
the value or null if no value is associated with the key
Throws:
NullPointerException - if the key is null

getKeyForValue

public K getKeyForValue(V value)
Gets the key that is associated with the given value.

Parameters:
value - value
Returns:
the key or null if no key is associated with the value
Throws:
NullPointerException - if the value is null


Copyright © 2007-2009. All Rights Reserved.