Class Index<K,​V>

java.lang.Object
net.kyori.adventure.util.Index<K,​V>
Type Parameters:
K - the key type
V - the value type

public final class Index<K,​V>
extends Object
A bi-directional map in which keys and values must be unique.
Since:
4.0.0
  • Method Summary

    Modifier and Type Method Description
    static <K,​ V> @NotNull Index<K,​V> create​(@NotNull Function<? super V,​? extends K> keyFunction, @NotNull List<V> constants)
    Creates an index map.
    static <K,​ V> @NotNull Index<K,​V> create​(@NotNull Function<? super V,​? extends K> keyFunction, @NotNull V @NotNull ... values)
    Creates an index map.
    static <K,​ V extends Enum<V>>
    @NotNull Index<K,​V>
    create​(Class<V> type, @NotNull Function<? super V,​? extends K> keyFunction)
    Creates an index map.
    static <K,​ V extends Enum<V>>
    @NotNull Index<K,​V>
    create​(Class<V> type, @NotNull Function<? super V,​? extends K> keyFunction, @NotNull V @NotNull ... values)
    Creates an index map.
    K key​(V value)
    Gets the key for a value.
    @NotNull Set<K> keys()
    Gets the keys.
    V value​(K key)
    Gets a value by its key.
    @NotNull Set<V> values()
    Gets the keys.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      @NotNull public static <K,​ V extends Enum<V>> @NotNull Index<K,​V> create​(Class<V> type, @NotNull @NotNull Function<? super V,​? extends K> keyFunction)
      Creates an index map.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      type - the value type
      keyFunction - the key function
      Returns:
      the key map
      Since:
      4.0.0
    • create

      @SafeVarargs @NotNull public static <K,​ V extends Enum<V>> @NotNull Index<K,​V> create​(Class<V> type, @NotNull @NotNull Function<? super V,​? extends K> keyFunction, @NotNull @NotNull V @NotNull ... values)
      Creates an index map.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      type - the value type
      keyFunction - the key function
      values - the values
      Returns:
      the key map
      Since:
      4.0.0
    • create

      @SafeVarargs @NotNull public static <K,​ V> @NotNull Index<K,​V> create​(@NotNull @NotNull Function<? super V,​? extends K> keyFunction, @NotNull @NotNull V @NotNull ... values)
      Creates an index map.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      keyFunction - the key function
      values - the values
      Returns:
      the key map
      Since:
      4.0.0
    • create

      @NotNull public static <K,​ V> @NotNull Index<K,​V> create​(@NotNull @NotNull Function<? super V,​? extends K> keyFunction, @NotNull @NotNull List<V> constants)
      Creates an index map.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      keyFunction - the key function
      constants - the constants
      Returns:
      the key map
      Since:
      4.0.0
    • keys

      @NotNull public @NotNull Set<K> keys()
      Gets the keys.
      Returns:
      the keys
      Since:
      4.0.0
    • key

      @Nullable public K key​(@NotNull V value)
      Gets the key for a value.
      Parameters:
      value - the value
      Returns:
      the key
      Since:
      4.0.0
    • values

      @NotNull public @NotNull Set<V> values()
      Gets the keys.
      Returns:
      the keys
      Since:
      4.0.0
    • value

      @Nullable public V value​(@NotNull K key)
      Gets a value by its key.
      Parameters:
      key - the key
      Returns:
      the value
      Since:
      4.0.0