Class MapUtil

java.lang.Object
org.fulib.fx.util.MapUtil

public class MapUtil extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isMapWithTypes(@NotNull Field field, @NotNull Class<?> key, @NotNull Class<?> value)
    Checks if the given field is a map with the given key and value types.
    static boolean
    isMapWithTypes(@NotNull Parameter parameter, @NotNull Class<?> key, @NotNull Class<?> value)
    Checks if the given parameter is a map with the given key and value types.
    static <T, E> T
    keyForValue(@NotNull Map<@NotNull T,@NotNull E> map, E value)
    Returns the key for the given value in the given map.
    static <T, E> E
    putIfNull(@NotNull Map<@NotNull T,@NotNull E> map, T key, E value)
    Inserts the given key and value into the given map if the key is not already present or is null.

    Methods inherited from class java.lang.Object

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

    • keyForValue

      @Nullable public static <T, E> T keyForValue(@NotNull @NotNull Map<@NotNull T,@NotNull E> map, @NotNull E value)
      Returns the key for the given value in the given map.
      Type Parameters:
      T - The type of the key
      E - The type of the value
      Parameters:
      map - The map to search in
      value - The value to search for
      Returns:
      The key for the given value in the given map or null if the value is not in the map
    • putIfNull

      @NotNull public static <T, E> E putIfNull(@NotNull @NotNull Map<@NotNull T,@NotNull E> map, @NotNull T key, @NotNull E value)
      Inserts the given key and value into the given map if the key is not already present or is null. If the key is already present (not null), the value will not be inserted.

      If the key is already present, the value for the key will be returned.

      Type Parameters:
      T - The type of the key
      E - The type of the value
      Parameters:
      map - The map to insert the key and value into
      key - The key to insert
      value - The value to insert
      Returns:
      The value for the key if the key is already present, the new value otherwise
    • isMapWithTypes

      public static boolean isMapWithTypes(@NotNull @NotNull Parameter parameter, @NotNull @NotNull Class<?> key, @NotNull @NotNull Class<?> value)
      Checks if the given parameter is a map with the given key and value types.

      This will not work for maps not directly specifying the generic types, such as MyMap extends HashMap<Key, Value>.

      Parameters:
      parameter - The parameter to check
      key - The key type
      value - The value type
      Returns:
      True if the parameter is a valid map field with the given key and value types
    • isMapWithTypes

      public static boolean isMapWithTypes(@NotNull @NotNull Field field, @NotNull @NotNull Class<?> key, @NotNull @NotNull Class<?> value)
      Checks if the given field is a map with the given key and value types.

      This will not work for maps not directly specifying the generic types, such as MyMap extends HashMap<Key, Value>.

      Parameters:
      field - The field to check
      key - The key type
      value - The value type
      Returns:
      True if the parameter is a valid map field with the given key and value types