Package javachess.model
Class BiMap<T1,T2>
java.lang.Object
javachess.model.BiMap<T1,T2>
- Type Parameters:
T1- The type of the first keyT2- The type of the second key
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets whether the BiMap contains a key or not.booleancontainsReverse(T2 value) Gets whether the BiMap contains a value or not.Gets the value associated with the key.getReverse(T2 key) Gets the key associated with the value.keySet()Gets the key set of the BiMap.voidPuts a key-value pair in the BiMap.voidRemoves a key-value pair from the BiMap.voidremoveReverse(T2 key) Removes a key-value pair from the BiMap using the reverse mapping.Gets the value set of the BiMap.toString()
-
Constructor Details
-
BiMap
public BiMap()
-
-
Method Details
-
put
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 mapvalue- The value to put in the map
-
remove
Removes a key-value pair from the BiMap.- Parameters:
key- The key to remove
-
removeReverse
Removes a key-value pair from the BiMap using the reverse mapping.- Parameters:
key- The value to remove
-
get
Gets the value associated with the key.- Parameters:
key- The key to get the value for- Returns:
- The value associated with the key
-
getReverse
Gets the key associated with the value.- Parameters:
key- The value to get the key for- Returns:
- The key associated with the value
-
contains
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
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
Gets the key set of the BiMap.- Returns:
- The key set of the BiMap
-
reverseKeySet
Gets the value set of the BiMap.- Returns:
- The value set of the BiMap
-
toString
-