Class BiHashMap<K,V>

java.lang.Object
jadex.collection.BiHashMap<K,V>
All Implemented Interfaces:
Map<K,V>

public class BiHashMap<K,V> extends Object implements Map<K,V>
A bidirectional hash map. Note using this implies a bijection (1:1 relation).
  • Field Details

    • forward

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

      protected Map<V,K> reverse
      The reverse map.
  • Constructor Details

    • BiHashMap

      public BiHashMap()
    • BiHashMap

      public BiHashMap(Map<K,V> forward, Map<V,K> reverse)
  • Method Details

    • clear

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

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

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

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

      public Set<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(Object key)
      Returns the value of the key from the forward map.
      Specified by:
      get in interface Map<K,V>
      Returns:
      The value.
    • rget

      public K rget(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 Map<K,V>
      Returns:
      True, if empty.
    • keySet

      public Set<K> keySet()
      Returns the keys of the forward map.
      Specified by:
      keySet in interface 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 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 Map<K,V>
      Returns:
      The size of the map.
    • remove

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

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

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

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

      public Collection<V> values()
      Returns the keys of the reverse map.
      Specified by:
      values in interface 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.