Package org.glassfish.admin.amx.util
Class MapUtil
- java.lang.Object
-
- org.glassfish.admin.amx.util.MapUtil
-
public final class MapUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object[]
getKeyObjects(Map<?,?> m)
static String[]
getKeyStrings(Map<?,?> m)
static <K> Set<K>
getNullValueKeys(Map<K,?> map)
Gets all keys which map to a null valuestatic <K,V>
VgetWithDefault(Map<K,V> m, K key, V defaultValue)
static boolean
isAllStrings(Map<?,?> map)
static boolean
mapsEqual(Map<?,?> map1, Map<?,?> map2)
static <K,V>
Map<K,V>newMap()
assignable to any map type, keeps things short on the rhsstatic Map<String,String>
newMap(String... mappings)
Create a new Map and insert the specified mappings as found in 'mappings'.static <V> Map<String,V>
newMap(String key, V value)
Create a new Map consisting of a single key/value pair.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.static <T> Map<T,T>
newMap(T... mappings)
Create a new Map and insert the specified mappings as found in 'mappings'.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 nullstatic <K> void
removeAll(Map<K,?> map, Set<K> keySet)
Removes all keys in a set from a mapstatic <T> void
removeAll(Map<T,?> map, T[] keys)
Remove all entries keyed by 'keys'static <K,V>
Map<K,V>toMap(Object[] params, Class<K> keyClass, Class<V> valueClass)
static <K,V>
Map<K,V>toMap(Properties props, Class<K> kClass, Class<V> vClass)
static String
toString(Map<?,?> m)
static String
toString(Map<?,?> map, String separator)
static Map<String,String>
toStringStringMap(Map<?,?> map)
Convert an arbitrary Map to one whose keys and values are both of type String.
-
-
-
Method Detail
-
getWithDefault
public static <K,V> V getWithDefault(Map<K,V> m, K key, V defaultValue)
-
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'
-
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
-
getNullValueKeys
public static <K> Set<K> getNullValueKeys(Map<K,?> map)
Gets all keys which map to a null value
-
toMap
public static <K,V> Map<K,V> toMap(Properties props, Class<K> kClass, Class<V> vClass)
-
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 fromkeySet
- 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
-
-