Class DualHashBidiMap<K,​V>

  • Type Parameters:
    K - the type of the keys in the map
    V - the type of the values in the map
    All Implemented Interfaces:
    java.io.Serializable, java.util.Map<K,​V>, BidiMap<K,​V>, IterableMap<K,​V>

    public class DualHashBidiMap<K,​V>
    extends AbstractDualBidiMap<K,​V>
    implements java.io.Serializable
    Implementation of BidiMap that uses two HashMap instances.

    Two HashMap instances are used in this class. This provides fast lookups at the expense of storing two sets of map entries. Commons Collections would welcome the addition of a direct hash-based implementation of the BidiMap interface.

    NOTE: From Commons Collections 3.1, all subclasses will use HashMap and the flawed createMap method is ignored.

    Since:
    3.0
    See Also:
    Serialized Form
    • Constructor Detail

      • DualHashBidiMap

        public DualHashBidiMap()
        Creates an empty HashBidiMap.
      • DualHashBidiMap

        public DualHashBidiMap​(java.util.Map<? extends K,​? extends V> map)
        Constructs a HashBidiMap and copies the mappings from specified Map.
        Parameters:
        map - the map whose mappings are to be placed in this map
      • DualHashBidiMap

        protected DualHashBidiMap​(java.util.Map<K,​V> normalMap,
                                  java.util.Map<V,​K> reverseMap,
                                  BidiMap<V,​K> inverseBidiMap)
        Constructs a HashBidiMap that decorates the specified maps.
        Parameters:
        normalMap - the normal direction map
        reverseMap - the reverse direction map
        inverseBidiMap - the inverse BidiMap
    • Method Detail

      • createBidiMap

        protected BidiMap<V,​K> createBidiMap​(java.util.Map<V,​K> normalMap,
                                                   java.util.Map<K,​V> reverseMap,
                                                   BidiMap<K,​V> inverseBidiMap)
        Creates a new instance of this object.
        Specified by:
        createBidiMap in class AbstractDualBidiMap<K,​V>
        Parameters:
        normalMap - the normal direction map
        reverseMap - the reverse direction map
        inverseBidiMap - the inverse BidiMap
        Returns:
        new bidi map