Class BidirectionalMap<K,​V>

  • Type Parameters:
    K - the type of the key
    V - the type of the value

    public class BidirectionalMap<K,​V>
    extends java.lang.Object
    Convenience class for mapping keys to values and vice versa. Both, keys and values, have to be unique.
    Since:
    1.5
    Author:
    emuller
    • Constructor Summary

      Constructors 
      Constructor Description
      BidirectionalMap()
      Default constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      K getByValue​(V value)
      Returns the key belonging to the given value.
      V getValue​(K key)
      Returns the value belonging to the given key.
      java.util.Set<K> keys()
      Returns all keys.
      void put​(K key, V value)
      Associates the specified value with the specified key in this map and vice versa.
      V removeByKey​(K key)
      Removes the bidirectional mapping for the given key.
      K removeByValue​(V value)
      Removes the bidirectional mapping for the given value.
      java.util.Set<V> values()
      Returns all values.
      • Methods inherited from class java.lang.Object

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

      • BidirectionalMap

        public BidirectionalMap()
        Default constructor.
    • Method Detail

      • put

        public void put​(K key,
                        V value)
        Associates the specified value with the specified key in this map and vice versa.
        Parameters:
        key - the key
        value - the value
      • removeByKey

        public V removeByKey​(K key)
        Removes the bidirectional mapping for the given key.
        Parameters:
        key - the key to be removed
        Returns:
        the value that was associated with the key
      • removeByValue

        public K removeByValue​(V value)
        Removes the bidirectional mapping for the given value.
        Parameters:
        value - the value to be removed
        Returns:
        the key that was associated with the value
      • getValue

        public V getValue​(K key)
        Returns the value belonging to the given key.
        Parameters:
        key - the key whose value should be looked up
        Returns:
        the value belonging to the given key
      • getByValue

        public K getByValue​(V value)
        Returns the key belonging to the given value.
        Parameters:
        value - the key whose value should be looked up
        Returns:
        the key belonging to the given value
      • keys

        public java.util.Set<K> keys()
        Returns all keys.
        Returns:
        a set of all keys
      • values

        public java.util.Set<V> values()
        Returns all values.
        Returns:
        a set of all values