Class TwoWayHashmap<K,​V>

  • Type Parameters:
    K - the key parameter type
    V - the value parameter type
    All Implemented Interfaces:
    java.io.Serializable

    public class TwoWayHashmap<K,​V>
    extends java.lang.Object
    implements java.io.Serializable
    A class to have a bi-directional map.
    Author:
    Anthony Bradley From here: http://stackoverflow.com/questions/3430170/how-to-create-a-2-way-map-in-java
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      TwoWayHashmap()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(K key, V value)
      Add a new key value pair
      K getBackward​(V value)
      Get a value using a key in the backward way.
      V getForward​(K key)
      Get a value using a key in the conventional way.
      • Methods inherited from class java.lang.Object

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

      • TwoWayHashmap

        public TwoWayHashmap()
    • Method Detail

      • add

        public void add​(K key,
                        V value)
        Add a new key value pair
        Parameters:
        key - the key
        value - the value
      • getForward

        public V getForward​(K key)
        Get a value using a key in the conventional way.
        Parameters:
        key - the input key
        Returns:
        the value
      • getBackward

        public K getBackward​(V value)
        Get a value using a key in the backward way.
        Parameters:
        value - the input value
        Returns:
        the key