Package org.fulib.fx.util
Class MapUtil
java.lang.Object
org.fulib.fx.util.MapUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisMapWithTypes(@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 booleanisMapWithTypes(@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 Inserts the given key and value into the given map if the key is not already present or is null.
-
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 keyE- The type of the value- Parameters:
map- The map to search invalue- 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 keyE- The type of the value- Parameters:
map- The map to insert the key and value intokey- The key to insertvalue- 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 checkkey- The key typevalue- 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 checkkey- The key typevalue- The value type- Returns:
- True if the parameter is a valid map field with the given key and value types
-