Class BiMap<K,​V>

  • Type Parameters:
    K - the type of the first key
    V - the type of the second key

    public final class BiMap<K,​V>
    extends java.lang.Object
    A simple bi-directional map.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<V,​K> inverseMap  
      private java.util.Map<K,​V> map  
    • Constructor Summary

      Constructors 
      Constructor Description
      BiMap()
      Creates a new BiMap instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      removes all entries from the map.
      boolean containsKey​(K k)
      Checks if the map contains the key.
      boolean containsValue​(V v)
      Checks if the map contains the value.
      V getByKey​(K value)
      Gets the value by key.
      K getByValue​(V key)
      Gets the key by value.
      boolean isEmpty()
      Checks if the map is empty.
      void put​(K k, V v)
      Puts the entry into the map.
      void removeByKey​(K k)
      Removes the entry by key.
      void removeByValue​(V v)
      Removes the entry by value.
      int size()
      Gets the size of the map.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • map

        private final java.util.Map<K,​V> map
      • inverseMap

        private final java.util.Map<V,​K> inverseMap
    • Constructor Detail

      • BiMap

        public BiMap()
        Creates a new BiMap instance.
    • Method Detail

      • put

        public void put​(K k,
                        V v)
        Puts the entry into the map. If the key already exists, the value will be overwritten. If the value already exists, the key will be overwritten. If both key and value already exist, the entry will be overwritten. If neither key nor value already exist, the entry will be added.
        Parameters:
        k - the key
        v - the value
      • getByKey

        public V getByKey​(K value)
        Gets the value by key.
        Parameters:
        value - the key
        Returns:
        the value
      • getByValue

        public K getByValue​(V key)
        Gets the key by value.
        Parameters:
        key - the value
        Returns:
        the key
      • removeByKey

        public void removeByKey​(K k)
        Removes the entry by key.
        Parameters:
        k - the key
      • removeByValue

        public void removeByValue​(V v)
        Removes the entry by value.
        Parameters:
        v - the value
      • size

        public int size()
        Gets the size of the map.
        Returns:
        the size of the map
      • clear

        public void clear()
        removes all entries from the map.
      • isEmpty

        public boolean isEmpty()
        Checks if the map is empty.
        Returns:
        true, if the map is empty
      • containsKey

        public boolean containsKey​(K k)
        Checks if the map contains the key.
        Parameters:
        k - the key
        Returns:
        true, if the map contains the key
      • containsValue

        public boolean containsValue​(V v)
        Checks if the map contains the value.
        Parameters:
        v - the value
        Returns:
        true, if the map contains the value