Class BiMap<T1,T2>

java.lang.Object
javachess.model.BiMap<T1,T2>
Type Parameters:
T1 - The type of the first key
T2 - The type of the second key

public class BiMap<T1,T2> extends Object
A BiMap is a bidirectional map that allows for two-way lookups. It maintains two HashMaps, one for each direction of the mapping. It has to be used on bijective data, meaning that each key can only have one value and vice versa.
  • Constructor Details

    • BiMap

      public BiMap()
  • Method Details

    • put

      public void put(T1 key, T2 value)
      Puts a key-value pair in the BiMap. If the key or value already exists, it removes the old pair.
      Parameters:
      key - The key to put in the map
      value - The value to put in the map
    • remove

      public void remove(T1 key)
      Removes a key-value pair from the BiMap.
      Parameters:
      key - The key to remove
    • removeReverse

      public void removeReverse(T2 key)
      Removes a key-value pair from the BiMap using the reverse mapping.
      Parameters:
      key - The value to remove
    • get

      public T2 get(T1 key)
      Gets the value associated with the key.
      Parameters:
      key - The key to get the value for
      Returns:
      The value associated with the key
    • getReverse

      public T1 getReverse(T2 key)
      Gets the key associated with the value.
      Parameters:
      key - The value to get the key for
      Returns:
      The key associated with the value
    • contains

      public boolean contains(T1 key)
      Gets whether the BiMap contains a key or not.
      Parameters:
      key - The key to check for
      Returns:
      True if the key is in the BiMap, false otherwise
    • containsReverse

      public boolean containsReverse(T2 value)
      Gets whether the BiMap contains a value or not. (reverse mapping)
      Parameters:
      value - The value to check for
      Returns:
      True if the value is in the BiMap, false otherwise
    • keySet

      public Set<T1> keySet()
      Gets the key set of the BiMap.
      Returns:
      The key set of the BiMap
    • reverseKeySet

      public Set<T2> reverseKeySet()
      Gets the value set of the BiMap.
      Returns:
      The value set of the BiMap
    • toString

      public String toString()
      Overrides:
      toString in class Object