Class BiHashMap<K,​V>

  • All Implemented Interfaces:
    java.util.Map<K,​V>

    public class BiHashMap<K,​V>
    extends java.lang.Object
    implements java.util.Map<K,​V>
    A bidirectional hash map. Note using this implies a bijection (1:1 relation).
    • Nested Class Summary

      • 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
      protected java.util.Map<K,​V> forward
      The forward map.
      protected java.util.Map<V,​K> reverse
      The reverse map.
    • Constructor Summary

      Constructors 
      Constructor Description
      BiHashMap()  
      BiHashMap​(java.util.Map<K,​V> forward, java.util.Map<V,​K> reverse)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the map.
      boolean containsKey​(java.lang.Object key)
      Returns whether the forward map contains the specified key.
      boolean containsValue​(java.lang.Object value)
      Returns whether the reverse map contains the specified key.
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
      Returns the entry set of the forward map.
      BiHashMap<V,​K> flip()
      Returns a flipped map, sharing the data with the original map.
      V get​(java.lang.Object key)
      Returns the value of the key from the forward map.
      boolean isEmpty()
      Tests if the map is empty.
      java.util.Set<K> keySet()
      Returns the keys of the forward map.
      V put​(K key, V value)
      Puts an entry into the map, forward direction.
      void putAll​(java.util.Map<? extends K,​? extends V> m)
      Puts all entries of a map into this map, forward direction.
      V remove​(java.lang.Object key)
      Removes an entry, forward direction.
      java.util.Set<java.util.Map.Entry<V,​K>> rentrySet()
      Returns the entry set of the reverse map.
      K rget​(java.lang.Object key)
      Returns the value of the key from the reverse map.
      void rputAll​(java.util.Map<? extends V,​? extends K> m)
      Puts all entries of a map into this map, reverse direction.
      K rremove​(java.lang.Object key)
      Removes an entry, reverse direction.
      int size()
      Returns the size of the map.
      java.util.Collection<V> values()
      Returns the keys of the reverse map.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • forward

        protected java.util.Map<K,​V> forward
        The forward map.
      • reverse

        protected java.util.Map<V,​K> reverse
        The reverse map.
    • Constructor Detail

      • BiHashMap

        public BiHashMap()
      • BiHashMap

        public BiHashMap​(java.util.Map<K,​V> forward,
                         java.util.Map<V,​K> reverse)
    • Method Detail

      • clear

        public void clear()
        Clears the map.
        Specified by:
        clear in interface java.util.Map<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Returns whether the forward map contains the specified key.
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        Parameters:
        key - The key.
        Returns:
        True, if the forward map contains key.
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Returns whether the reverse map contains the specified key.
        Specified by:
        containsValue in interface java.util.Map<K,​V>
        Parameters:
        key - The key.
        Returns:
        True, if the reverse map contains key.
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Returns the entry set of the forward map.
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Returns:
        The entry set of the forward map.
      • rentrySet

        public java.util.Set<java.util.Map.Entry<V,​K>> rentrySet()
        Returns the entry set of the reverse map.
        Returns:
        The entry set of the reverse map.
      • get

        public V get​(java.lang.Object key)
        Returns the value of the key from the forward map.
        Specified by:
        get in interface java.util.Map<K,​V>
        Returns:
        The value.
      • rget

        public K rget​(java.lang.Object key)
        Returns the value of the key from the reverse map.
        Returns:
        The value.
      • isEmpty

        public boolean isEmpty()
        Tests if the map is empty.
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
        Returns:
        True, if empty.
      • keySet

        public java.util.Set<K> keySet()
        Returns the keys of the forward map.
        Specified by:
        keySet in interface java.util.Map<K,​V>
        Returns:
        The keys.
      • put

        public V put​(K key,
                     V value)
        Puts an entry into the map, forward direction.
        Specified by:
        put in interface java.util.Map<K,​V>
        Parameters:
        key - The key.
        value - The value.
        Returns:
        The value.
      • size

        public int size()
        Returns the size of the map.
        Specified by:
        size in interface java.util.Map<K,​V>
        Returns:
        The size of the map.
      • remove

        public V remove​(java.lang.Object key)
        Removes an entry, forward direction.
        Specified by:
        remove in interface java.util.Map<K,​V>
        Parameters:
        key - The entry key.
        Returns:
        The removed value.
      • rremove

        public K rremove​(java.lang.Object key)
        Removes an entry, reverse direction.
        Parameters:
        key - The entry key.
        Returns:
        The removed value.
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> m)
        Puts all entries of a map into this map, forward direction.
        Specified by:
        putAll in interface java.util.Map<K,​V>
        Parameters:
        m - The map.
      • rputAll

        public void rputAll​(java.util.Map<? extends V,​? extends K> m)
        Puts all entries of a map into this map, reverse direction.
        Parameters:
        m - The map.
      • values

        public java.util.Collection<V> values()
        Returns the keys of the reverse map.
        Specified by:
        values in interface java.util.Map<K,​V>
        Returns:
        The keys.
      • flip

        public BiHashMap<V,​K> flip()
        Returns a flipped map, sharing the data with the original map.
        Returns:
        Map with keys and values reversed.