Interface BiMap<K,V>

All Superinterfaces:
Map<K,V>
All Known Implementing Classes:
BiMap.CopyMapWrapper, BiMap.MapWrapper

@API(status=STABLE) public interface BiMap<K,V> extends Map<K,V>
Simple bi-map implementation using two independent hash maps for fast reverse lookup, while giving up double the memory. This interface also extends the standard Map to ensure compatibility with third-party- or standard-APIs.
Since:
10/05/2022
  • Method Details

    • wrap

      static <K, V> BiMap<K,V> wrap(Map<K,V> map)
      Creates a wrapper instance around the given map, allowing direct access to the underlying map through the interface's functions while using loops for reverse-lookups.

      This should be used when there is a lot of BiMap allocations (meaning the maps themselves being allocated).

      Type Parameters:
      K - The key type of the given map.
      V - The value type of the given map.
      Parameters:
      map - The map to create a wrapper around.
      Returns:
      A new wrapper instance with access to the given map.
    • copyOf

      static <K, V> BiMap<K,V> copyOf(Map<K,V> map)
      Creates an immutable wrapper instance around the given map, not allowing direct access to the underlying map through the interface's functions, but creating two copies of the given map, one reversed for faster lookups.

      This should be used when there are fewer allocations of the maps themselves, and more concern about the lookup times in both directions of the map.

      Type Parameters:
      K - The key type of the given map.
      V - The value type of the given map.
      Parameters:
      map - The map to create a wrapper around.
      Returns:
      A copy of the given map in form of a new BiMap instance.
    • getForValue

      @Nullable K getForValue(@Nullable V value)