Class MapUtils

java.lang.Object
me.hsgamer.hscore.common.MapUtils

public class MapUtils extends Object
Methods on Map
  • Method Details

    • getIfFoundOrDefault

      @SafeVarargs public static <K, V> V getIfFoundOrDefault(Map<K,V> map, V defaultValue, K... key)
      Get the value given the key from the map
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map - the map
      defaultValue - the default value
      key - the key
      Returns:
      the value
    • getIfFound

      @SafeVarargs public static <K, V> V getIfFound(Map<K,V> map, K... key)
      Get the value given the key from the map
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map - the map
      key - the key
      Returns:
      the value, or null if not found
    • getOptional

      @SafeVarargs public static <K, V> Optional<V> getOptional(Map<K,V> map, K... key)
      Get the value given the key from the map
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map - the map
      key - the key
      Returns:
      the value, or empty optional if not found
    • containsAnyKey

      @SafeVarargs public static <K> boolean containsAnyKey(Map<K,?> map, K... key)
      Check if the map contains any of the keys
      Type Parameters:
      K - the key type
      Parameters:
      map - the map
      key - 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 object
      unsafe - 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

      public static Optional<Map<String,Object>> castOptionalStringObjectMap(Object object)
      Cast to the optional string-object map
      Parameters:
      object - the object
      Returns:
      the map