Class 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 extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private BiMap _inverse
      the inverse
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        BiMap()
      Constructor
      private BiMap​(BiMap inverse)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, 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