org.onemind.commons.java.datastructure
Class BiMap

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap
          extended by org.onemind.commons.java.datastructure.BiMap
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map

public class BiMap
extends java.util.HashMap

A simple bi-directional map. It uses another map to store the inverse of this map. The key has to be unique in key space and the value need to be unique in the value space so that the value can be resolved to the key correctly. This class is not thread safe.

Version:
$Id: BiMap.java,v 1.1 2004/09/29 02:45:35 thlee Exp $ $Name: $
Author:
TiongHiang Lee (thlee@onemindsoft.org)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
private  BiMap _inverse
          the inverse
 
Constructor Summary
  BiMap()
          Constructor
private BiMap(BiMap inverse)
          Constructor
 
Method Summary
 void clear()
          
 BiMap getInverse()
          Get the inverse bimap
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          
private  java.lang.Object rawPut(java.lang.Object key, java.lang.Object value)
          Put the key value association with super.put()
private  java.lang.Object rawRemove(java.lang.Object key)
          Remove the key
 java.lang.Object remove(java.lang.Object key)
          
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

_inverse

private final BiMap _inverse
the inverse

Constructor Detail

BiMap

public BiMap()
Constructor


BiMap

private BiMap(BiMap inverse)
Constructor

Parameters:
map - the inverse
Method Detail

getInverse

public BiMap getInverse()
Get the inverse bimap

Returns:
the bimap

clear

public void clear()

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

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)

Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.HashMap

rawPut

private java.lang.Object rawPut(java.lang.Object key,
                                java.lang.Object value)
Put the key value association with super.put()

Parameters:
key - the key
value - the value

rawRemove

private java.lang.Object rawRemove(java.lang.Object key)
Remove the key

Parameters:
key - the key
Returns:
the value by super.remove();

remove

public java.lang.Object remove(java.lang.Object key)

Specified by:
remove in interface java.util.Map
Overrides:
remove in class java.util.HashMap