Class MapUtil


  • public final class MapUtil
    extends Object
    The utility class for Map
    • Method Detail

      • 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
      • 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)
        Cast to the optional string-object map
        Parameters:
        object - the object
        Returns:
        the map