Class MapUtil


  • public final class MapUtil
    extends Object
    • Method Detail

      • getWithDefault

        public static <K,​V> V getWithDefault​(Map<K,​V> m,
                                                   K key,
                                                   V defaultValue)
      • getKeyObjects

        public static Object[] getKeyObjects​(Map<?,​?> m)
      • getKeyStrings

        public static String[] getKeyStrings​(Map<?,​?> m)
      • newMap

        public static <K,​V> Map<K,​V> newMap()
        assignable to any map type, keeps things short on the rhs
      • newMap

        public static <V> Map<String,​V> newMap​(String key,
                                                     V value)
        Create a new Map consisting of a single key/value pair.
      • newMap

        public static <K,​V> Map<K,​V> newMap​(Map<K,​V> m1,
                                                        Map<K,​V> m2)
        Create a new Map combined all entries of two other maps. If a key is is both maps then the value in map2 will be used.
      • toMap

        public static <K,​V> Map<K,​V> toMap​(Object[] params,
                                                       Class<K> keyClass,
                                                       Class<V> valueClass)
      • newMap

        public static <T> Map<T,​T> newMap​(T... mappings)
        Create a new Map and insert the specified mappings as found in 'mappings'. The even-numbered entries are the keys, and the odd-numbered entries are the values.
      • newMap

        public static Map<String,​String> newMap​(String... mappings)
        Create a new Map and insert the specified mappings as found in 'mappings'. The even-numbered entries are the keys, and the odd-numbered entries are the values.
      • removeAll

        public static <T> void removeAll​(Map<T,​?> map,
                                         T[] keys)
        Remove all entries keyed by 'keys'
      • mapsEqual

        public static boolean mapsEqual​(Map<?,​?> map1,
                                        Map<?,​?> map2)
      • newMapNoNullValues

        public static <K,​V> Map<K,​V> newMapNoNullValues​(Map<K,​V> map)
        Creates a new map with all the old key/value pairs unless the value was null
        Parameters:
        map - the old map to convert
        Returns:
        a new map with no null values
      • toString

        public static String toString​(Map<?,​?> m)
      • toString

        public static String toString​(Map<?,​?> map,
                                      String separator)
      • getNullValueKeys

        public static <K> Set<K> getNullValueKeys​(Map<K,​?> map)
        Gets all keys which map to a null value
      • removeAll

        public static <K> void removeAll​(Map<K,​?> map,
                                         Set<K> keySet)
        Removes all keys in a set from a map
        Parameters:
        map - the map to remove keys from
        keySet - a set of keys to remove
      • isAllStrings

        public static boolean isAllStrings​(Map<?,​?> map)
        Returns:
        true if non-null Map and all keys and values are of type java.lang.String
      • toStringStringMap

        public static Map<String,​String> toStringStringMap​(Map<?,​?> map)
        Convert an arbitrary Map to one whose keys and values are both of type String.