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 keyscreateLowercaseStringMap(Map<String, V> map) Create aLinkedHashMapwith lowercase keyscreateLowercaseStringMap(Map<String, V> map, Supplier<M> mapSupplier) Create a new 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
-
createLowercaseStringMap
public static <V,M extends Map<String, M createLowercaseStringMapV>> (Map<String, V> map, Supplier<M> mapSupplier) Create a new map with lowercase keys- Type Parameters:
V- the value typeM- the map type- Parameters:
map- the mapmapSupplier- the map constructor- Returns:
- the new map
-
createLowercaseStringMap
Create aLinkedHashMapwith lowercase keys- Type Parameters:
V- the value type- Parameters:
map- the map- Returns:
- the new map
-