Package me.hsgamer.hscore.common
Class MapUtils
java.lang.Object
me.hsgamer.hscore.common.MapUtils
Methods on Map
-
Method Summary
Modifier and TypeMethodDescriptioncastOptionalStringObjectMap(Object object) Cast to the optional string-object mapcastOptionalStringObjectMap(Object object, boolean unsafe) Cast to the optional string-object mapstatic <K> booleancontainsAnyKey(Map<K, ?> map, K... key) Check if the map contains any of the keyscreateLowercaseStringObjectMap(Map<?, ?> map) Create a string-objectLinkedHashMapwith lowercase keyscreateLowercaseStringObjectMap(Map<?, ?> map, Supplier<M> mapSupplier) Create a new string-object map with lowercase keysstatic <K,V> V getIfFound(Map<K, V> map, K... key) Get the value given the key from the mapstatic <K,V> V getIfFoundOrDefault(Map<K, V> map, V defaultValue, K... key) Get the value given the key from the mapstatic <K,V> Optional <V> getOptional(Map<K, V> map, K... key) Get the value given the key from the map
-
Method Details
-
getIfFoundOrDefault
Get the value given the key from the map- Type Parameters:
K- the key typeV- the value type- Parameters:
map- the mapdefaultValue- the default valuekey- the key- Returns:
- the value
-
getIfFound
Get the value given the key from the map- Type Parameters:
K- the key typeV- the value type- Parameters:
map- the mapkey- the key- Returns:
- the value, or null if not found
-
getOptional
Get the value given the key from the map- Type Parameters:
K- the key typeV- the value type- Parameters:
map- the mapkey- the key- Returns:
- the value, or empty optional if not found
-
containsAnyKey
Check if the map contains any of the keys- Type Parameters:
K- the key type- Parameters:
map- the mapkey- the key- Returns:
- true if it does
-
castOptionalStringObjectMap
public static Optional<Map<String,Object>> castOptionalStringObjectMap(Object object, boolean unsafe) Cast to the optional string-object map- Parameters:
object- the objectunsafe- whether to cast unsafe. Set to false if you want to ensure the map is string-object map, but it will be slower.- Returns:
- the map, or empty optional if it's not a map
-
castOptionalStringObjectMap
Cast to the optional string-object map- Parameters:
object- the object- Returns:
- the map
-
createLowercaseStringObjectMap
public static <M extends Map<String,Object>> M createLowercaseStringObjectMap(Map<?, ?> map, Supplier<M> mapSupplier) Create a new string-object map with lowercase keys- Type Parameters:
M- the map type- Parameters:
map- the original mapmapSupplier- the map constructor- Returns:
- the new map
-
createLowercaseStringObjectMap
Create a string-objectLinkedHashMapwith lowercase keys- Parameters:
map- the original map- Returns:
- the new map
-