Class MapUtils
- java.lang.Object
-
- org.apache.commons.collections.MapUtils
-
@Deprecated(since="2021-04-30") public class MapUtils extends java.lang.Object
Deprecated.Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.Provides utility methods and decorators forMap
andSortedMap
instances.It contains various type safe methods as well as other useful features like deep copying.
It also provides the following decorators:
fixedSizeMap(Map)
fixedSizeSortedMap(SortedMap)
lazyMap(Map,Factory)
lazyMap(Map,Transformer)
lazySortedMap(SortedMap,Factory)
lazySortedMap(SortedMap,Transformer)
predicatedMap(Map,Predicate,Predicate)
predicatedSortedMap(SortedMap,Predicate,Predicate)
transformedMap(Map, Transformer, Transformer)
transformedSortedMap(SortedMap, Transformer, Transformer)
typedMap(Map, Class, Class)
typedSortedMap(SortedMap, Class, Class)
multiValueMap( Map )
multiValueMap( Map, Class )
multiValueMap( Map, Factory )
- Since:
- Commons Collections 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Map
EMPTY_MAP
Deprecated.An empty unmodifiable map.static java.util.SortedMap
EMPTY_SORTED_MAP
Deprecated.An empty unmodifiable sorted map.
-
Constructor Summary
Constructors Constructor Description MapUtils()
Deprecated.MapUtils
should not normally be instantiated.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
debugPrint(java.io.PrintStream out, java.lang.Object label, java.util.Map map)
Deprecated.Prints the given map with nice line breaks.static java.util.Map
fixedSizeMap(java.util.Map map)
Deprecated.Returns a fixed-sized map backed by the given map.static java.util.SortedMap
fixedSizeSortedMap(java.util.SortedMap map)
Deprecated.Returns a fixed-sized sorted map backed by the given sorted map.static java.lang.Boolean
getBoolean(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Boolean from a Map in a null-safe manner.static java.lang.Boolean
getBoolean(java.util.Map map, java.lang.Object key, java.lang.Boolean defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a boolean, using the default value if the the conversion fails.static boolean
getBooleanValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a boolean from a Map in a null-safe manner.static boolean
getBooleanValue(java.util.Map map, java.lang.Object key, boolean defaultValue)
Deprecated.Gets a boolean from a Map in a null-safe manner, using the default value if the the conversion fails.static java.lang.Byte
getByte(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Byte from a Map in a null-safe manner.static java.lang.Byte
getByte(java.util.Map map, java.lang.Object key, java.lang.Byte defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a byte, using the default value if the the conversion fails.static byte
getByteValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a byte from a Map in a null-safe manner.static byte
getByteValue(java.util.Map map, java.lang.Object key, byte defaultValue)
Deprecated.Gets a byte from a Map in a null-safe manner, using the default value if the the conversion fails.static java.lang.Double
getDouble(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Double from a Map in a null-safe manner.static java.lang.Double
getDouble(java.util.Map map, java.lang.Object key, java.lang.Double defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a double, using the default value if the the conversion fails.static double
getDoubleValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a double from a Map in a null-safe manner.static double
getDoubleValue(java.util.Map map, java.lang.Object key, double defaultValue)
Deprecated.Gets a double from a Map in a null-safe manner, using the default value if the the conversion fails.static java.lang.Float
getFloat(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Float from a Map in a null-safe manner.static java.lang.Float
getFloat(java.util.Map map, java.lang.Object key, java.lang.Float defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a float, using the default value if the the conversion fails.static float
getFloatValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a float from a Map in a null-safe manner.static float
getFloatValue(java.util.Map map, java.lang.Object key, float defaultValue)
Deprecated.Gets a float from a Map in a null-safe manner, using the default value if the the conversion fails.static java.lang.Integer
getInteger(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Integer from a Map in a null-safe manner.static java.lang.Integer
getInteger(java.util.Map map, java.lang.Object key, java.lang.Integer defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into an integer, using the default value if the the conversion fails.static int
getIntValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets an int from a Map in a null-safe manner.static int
getIntValue(java.util.Map map, java.lang.Object key, int defaultValue)
Deprecated.Gets an int from a Map in a null-safe manner, using the default value if the the conversion fails.static java.lang.Long
getLong(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Long from a Map in a null-safe manner.static java.lang.Long
getLong(java.util.Map map, java.lang.Object key, java.lang.Long defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a long, using the default value if the the conversion fails.static long
getLongValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a long from a Map in a null-safe manner.static long
getLongValue(java.util.Map map, java.lang.Object key, long defaultValue)
Deprecated.Gets a long from a Map in a null-safe manner, using the default value if the the conversion fails.static java.util.Map
getMap(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Map from a Map in a null-safe manner.static java.util.Map
getMap(java.util.Map map, java.lang.Object key, java.util.Map defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a map, using the default value if the the conversion fails.static java.lang.Number
getNumber(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Number from a Map in a null-safe manner.static java.lang.Number
getNumber(java.util.Map map, java.lang.Object key, java.lang.Number defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a number, using the default value if the the conversion fails.static java.lang.Object
getObject(java.util.Map map, java.lang.Object key)
Deprecated.Gets from a Map in a null-safe manner.static java.lang.Object
getObject(java.util.Map map, java.lang.Object key, java.lang.Object defaultValue)
Deprecated.Looks up the given key in the given map, converting null into the given default value.static java.lang.Short
getShort(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Short from a Map in a null-safe manner.static java.lang.Short
getShort(java.util.Map map, java.lang.Object key, java.lang.Short defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a short, using the default value if the the conversion fails.static short
getShortValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a short from a Map in a null-safe manner.static short
getShortValue(java.util.Map map, java.lang.Object key, short defaultValue)
Deprecated.Gets a short from a Map in a null-safe manner, using the default value if the the conversion fails.static java.lang.String
getString(java.util.Map map, java.lang.Object key)
Deprecated.Gets a String from a Map in a null-safe manner.static java.lang.String
getString(java.util.Map map, java.lang.Object key, java.lang.String defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a string, using the default value if the the conversion fails.static java.util.Map
invertMap(java.util.Map map)
Deprecated.Inverts the supplied map returning a new HashMap such that the keys of the input are swapped with the values.static boolean
isEmpty(java.util.Map map)
Deprecated.Null-safe check if the specified map is empty.static boolean
isNotEmpty(java.util.Map map)
Deprecated.Null-safe check if the specified map is not empty.static java.util.Map
lazyMap(java.util.Map map, Factory factory)
Deprecated.Returns a "lazy" map whose values will be created on demand.static java.util.Map
lazyMap(java.util.Map map, Transformer transformerFactory)
Deprecated.Returns a "lazy" map whose values will be created on demand.static java.util.SortedMap
lazySortedMap(java.util.SortedMap map, Factory factory)
Deprecated.Returns a "lazy" sorted map whose values will be created on demand.static java.util.SortedMap
lazySortedMap(java.util.SortedMap map, Transformer transformerFactory)
Deprecated.Returns a "lazy" sorted map whose values will be created on demand.static java.util.Map
multiValueMap(java.util.Map map)
Deprecated.Creates a mult-value map backed by the given map which returns collections of type ArrayList.static java.util.Map
multiValueMap(java.util.Map map, java.lang.Class collectionClass)
Deprecated.Creates a multi-value map backed by the given map which returns collections of the specified type.static java.util.Map
multiValueMap(java.util.Map map, Factory collectionFactory)
Deprecated.Creates a multi-value map backed by the given map which returns collections created by the specified collection factory.static java.util.Map
orderedMap(java.util.Map map)
Deprecated.Returns a map that maintains the order of keys that are added backed by the given map.static java.util.Map
predicatedMap(java.util.Map map, Predicate keyPred, Predicate valuePred)
Deprecated.Returns a predicated (validating) map backed by the given map.static java.util.SortedMap
predicatedSortedMap(java.util.SortedMap map, Predicate keyPred, Predicate valuePred)
Deprecated.Returns a predicated (validating) sorted map backed by the given map.static java.util.Map
putAll(java.util.Map map, java.lang.Object[] array)
Deprecated.Puts all the keys and values from the specified array into the map.static void
safeAddToMap(java.util.Map map, java.lang.Object key, java.lang.Object value)
Deprecated.Protects against adding null values to a map.static java.util.Map
synchronizedMap(java.util.Map map)
Deprecated.Returns a synchronized map backed by the given map.static java.util.Map
synchronizedSortedMap(java.util.SortedMap map)
Deprecated.Returns a synchronized sorted map backed by the given sorted map.static java.util.Map
toMap(java.util.ResourceBundle resourceBundle)
Deprecated.Creates a new HashMap using data copied from a ResourceBundle.static java.util.Properties
toProperties(java.util.Map map)
Deprecated.Gets a new Properties object initialised with the values from a Map.static java.util.Map
transformedMap(java.util.Map map, Transformer keyTransformer, Transformer valueTransformer)
Deprecated.Returns a transformed map backed by the given map.static java.util.SortedMap
transformedSortedMap(java.util.SortedMap map, Transformer keyTransformer, Transformer valueTransformer)
Deprecated.Returns a transformed sorted map backed by the given map.static java.util.Map
typedMap(java.util.Map map, java.lang.Class keyType, java.lang.Class valueType)
Deprecated.Returns a typed map backed by the given map.static java.util.SortedMap
typedSortedMap(java.util.SortedMap map, java.lang.Class keyType, java.lang.Class valueType)
Deprecated.Returns a typed sorted map backed by the given map.static java.util.Map
unmodifiableMap(java.util.Map map)
Deprecated.Returns an unmodifiable map backed by the given map.static java.util.Map
unmodifiableSortedMap(java.util.SortedMap map)
Deprecated.Returns an unmodifiable sorted map backed by the given sorted map.static void
verbosePrint(java.io.PrintStream out, java.lang.Object label, java.util.Map map)
Deprecated.Prints the given map with nice line breaks.
-
-
-
Method Detail
-
getObject
public static java.lang.Object getObject(java.util.Map map, java.lang.Object key)
Deprecated.Gets from a Map in a null-safe manner.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map,
null
if null map input
-
getString
public static java.lang.String getString(java.util.Map map, java.lang.Object key)
Deprecated.Gets a String from a Map in a null-safe manner.The String is obtained via
toString
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a String,
null
if null map input
-
getBoolean
public static java.lang.Boolean getBoolean(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Boolean from a Map in a null-safe manner.If the value is a
Boolean
it is returned directly. If the value is aString
and it equals 'true' ignoring case thentrue
is returned, otherwisefalse
. If the value is aNumber
an integer zero value returnsfalse
and non-zero returnstrue
. Otherwise,null
is returned.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a Boolean,
null
if null map input
-
getNumber
public static java.lang.Number getNumber(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Number from a Map in a null-safe manner.If the value is a
Number
it is returned directly. If the value is aString
it is converted usingNumberFormat.parse(String)
on the system default formatter returningnull
if the conversion fails. Otherwise,null
is returned.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a Number,
null
if null map input
-
getByte
public static java.lang.Byte getByte(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Byte from a Map in a null-safe manner.The Byte is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a Byte,
null
if null map input
-
getShort
public static java.lang.Short getShort(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Short from a Map in a null-safe manner.The Short is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a Short,
null
if null map input
-
getInteger
public static java.lang.Integer getInteger(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Integer from a Map in a null-safe manner.The Integer is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a Integer,
null
if null map input
-
getLong
public static java.lang.Long getLong(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Long from a Map in a null-safe manner.The Long is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a Long,
null
if null map input
-
getFloat
public static java.lang.Float getFloat(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Float from a Map in a null-safe manner.The Float is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a Float,
null
if null map input
-
getDouble
public static java.lang.Double getDouble(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Double from a Map in a null-safe manner.The Double is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a Double,
null
if null map input
-
getMap
public static java.util.Map getMap(java.util.Map map, java.lang.Object key)
Deprecated.Gets a Map from a Map in a null-safe manner.If the value returned from the specified map is not a Map then
null
is returned.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a Map,
null
if null map input
-
getObject
public static java.lang.Object getObject(java.util.Map map, java.lang.Object key, java.lang.Object defaultValue)
Deprecated.Looks up the given key in the given map, converting null into the given default value.- Parameters:
map
- the map whose value to look upkey
- the key of the value to look up in that mapdefaultValue
- what to return if the value is null- Returns:
- the value in the map, or defaultValue if the original value is null or the map is null
-
getString
public static java.lang.String getString(java.util.Map map, java.lang.Object key, java.lang.String defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a string, using the default value if the the conversion fails.- Parameters:
map
- the map whose value to look upkey
- the key of the value to look up in that mapdefaultValue
- what to return if the value is null or if the conversion fails- Returns:
- the value in the map as a string, or defaultValue if the original value is null, the map is null or the string conversion fails
-
getBoolean
public static java.lang.Boolean getBoolean(java.util.Map map, java.lang.Object key, java.lang.Boolean defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a boolean, using the default value if the the conversion fails.- Parameters:
map
- the map whose value to look upkey
- the key of the value to look up in that mapdefaultValue
- what to return if the value is null or if the conversion fails- Returns:
- the value in the map as a boolean, or defaultValue if the original value is null, the map is null or the boolean conversion fails
-
getNumber
public static java.lang.Number getNumber(java.util.Map map, java.lang.Object key, java.lang.Number defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a number, using the default value if the the conversion fails.- Parameters:
map
- the map whose value to look upkey
- the key of the value to look up in that mapdefaultValue
- what to return if the value is null or if the conversion fails- Returns:
- the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversion fails
-
getByte
public static java.lang.Byte getByte(java.util.Map map, java.lang.Object key, java.lang.Byte defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a byte, using the default value if the the conversion fails.- Parameters:
map
- the map whose value to look upkey
- the key of the value to look up in that mapdefaultValue
- what to return if the value is null or if the conversion fails- Returns:
- the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversion fails
-
getShort
public static java.lang.Short getShort(java.util.Map map, java.lang.Object key, java.lang.Short defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a short, using the default value if the the conversion fails.- Parameters:
map
- the map whose value to look upkey
- the key of the value to look up in that mapdefaultValue
- what to return if the value is null or if the conversion fails- Returns:
- the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversion fails
-
getInteger
public static java.lang.Integer getInteger(java.util.Map map, java.lang.Object key, java.lang.Integer defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into an integer, using the default value if the the conversion fails.- Parameters:
map
- the map whose value to look upkey
- the key of the value to look up in that mapdefaultValue
- what to return if the value is null or if the conversion fails- Returns:
- the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversion fails
-
getLong
public static java.lang.Long getLong(java.util.Map map, java.lang.Object key, java.lang.Long defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a long, using the default value if the the conversion fails.- Parameters:
map
- the map whose value to look upkey
- the key of the value to look up in that mapdefaultValue
- what to return if the value is null or if the conversion fails- Returns:
- the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversion fails
-
getFloat
public static java.lang.Float getFloat(java.util.Map map, java.lang.Object key, java.lang.Float defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a float, using the default value if the the conversion fails.- Parameters:
map
- the map whose value to look upkey
- the key of the value to look up in that mapdefaultValue
- what to return if the value is null or if the conversion fails- Returns:
- the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversion fails
-
getDouble
public static java.lang.Double getDouble(java.util.Map map, java.lang.Object key, java.lang.Double defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a double, using the default value if the the conversion fails.- Parameters:
map
- the map whose value to look upkey
- the key of the value to look up in that mapdefaultValue
- what to return if the value is null or if the conversion fails- Returns:
- the value in the map as a number, or defaultValue if the original value is null, the map is null or the number conversion fails
-
getMap
public static java.util.Map getMap(java.util.Map map, java.lang.Object key, java.util.Map defaultValue)
Deprecated.Looks up the given key in the given map, converting the result into a map, using the default value if the the conversion fails.- Parameters:
map
- the map whose value to look upkey
- the key of the value to look up in that mapdefaultValue
- what to return if the value is null or if the conversion fails- Returns:
- the value in the map as a number, or defaultValue if the original value is null, the map is null or the map conversion fails
-
getBooleanValue
public static boolean getBooleanValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a boolean from a Map in a null-safe manner.If the value is a
Boolean
its value is returned. If the value is aString
and it equals 'true' ignoring case thentrue
is returned, otherwisefalse
. If the value is aNumber
an integer zero value returnsfalse
and non-zero returnstrue
. Otherwise,false
is returned.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a Boolean,
false
if null map input
-
getByteValue
public static byte getByteValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a byte from a Map in a null-safe manner.The byte is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a byte,
0
if null map input
-
getShortValue
public static short getShortValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a short from a Map in a null-safe manner.The short is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a short,
0
if null map input
-
getIntValue
public static int getIntValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets an int from a Map in a null-safe manner.The int is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as an int,
0
if null map input
-
getLongValue
public static long getLongValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a long from a Map in a null-safe manner.The long is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a long,
0L
if null map input
-
getFloatValue
public static float getFloatValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a float from a Map in a null-safe manner.The float is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a float,
0.0F
if null map input
-
getDoubleValue
public static double getDoubleValue(java.util.Map map, java.lang.Object key)
Deprecated.Gets a double from a Map in a null-safe manner.The double is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look up- Returns:
- the value in the Map as a double,
0.0
if null map input
-
getBooleanValue
public static boolean getBooleanValue(java.util.Map map, java.lang.Object key, boolean defaultValue)
Deprecated.Gets a boolean from a Map in a null-safe manner, using the default value if the the conversion fails.If the value is a
Boolean
its value is returned. If the value is aString
and it equals 'true' ignoring case thentrue
is returned, otherwisefalse
. If the value is aNumber
an integer zero value returnsfalse
and non-zero returnstrue
. Otherwise,defaultValue
is returned.- Parameters:
map
- the map to usekey
- the key to look updefaultValue
- return if the value is null or if the conversion fails- Returns:
- the value in the Map as a Boolean,
defaultValue
if null map input
-
getByteValue
public static byte getByteValue(java.util.Map map, java.lang.Object key, byte defaultValue)
Deprecated.Gets a byte from a Map in a null-safe manner, using the default value if the the conversion fails.The byte is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look updefaultValue
- return if the value is null or if the conversion fails- Returns:
- the value in the Map as a byte,
defaultValue
if null map input
-
getShortValue
public static short getShortValue(java.util.Map map, java.lang.Object key, short defaultValue)
Deprecated.Gets a short from a Map in a null-safe manner, using the default value if the the conversion fails.The short is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look updefaultValue
- return if the value is null or if the conversion fails- Returns:
- the value in the Map as a short,
defaultValue
if null map input
-
getIntValue
public static int getIntValue(java.util.Map map, java.lang.Object key, int defaultValue)
Deprecated.Gets an int from a Map in a null-safe manner, using the default value if the the conversion fails.The int is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look updefaultValue
- return if the value is null or if the conversion fails- Returns:
- the value in the Map as an int,
defaultValue
if null map input
-
getLongValue
public static long getLongValue(java.util.Map map, java.lang.Object key, long defaultValue)
Deprecated.Gets a long from a Map in a null-safe manner, using the default value if the the conversion fails.The long is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look updefaultValue
- return if the value is null or if the conversion fails- Returns:
- the value in the Map as a long,
defaultValue
if null map input
-
getFloatValue
public static float getFloatValue(java.util.Map map, java.lang.Object key, float defaultValue)
Deprecated.Gets a float from a Map in a null-safe manner, using the default value if the the conversion fails.The float is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look updefaultValue
- return if the value is null or if the conversion fails- Returns:
- the value in the Map as a float,
defaultValue
if null map input
-
getDoubleValue
public static double getDoubleValue(java.util.Map map, java.lang.Object key, double defaultValue)
Deprecated.Gets a double from a Map in a null-safe manner, using the default value if the the conversion fails.The double is obtained from the results of
getNumber(Map,Object)
.- Parameters:
map
- the map to usekey
- the key to look updefaultValue
- return if the value is null or if the conversion fails- Returns:
- the value in the Map as a double,
defaultValue
if null map input
-
toProperties
public static java.util.Properties toProperties(java.util.Map map)
Deprecated.Gets a new Properties object initialised with the values from a Map. A null input will return an empty properties object.- Parameters:
map
- the map to convert to a Properties object, may not be null- Returns:
- the properties object
-
toMap
public static java.util.Map toMap(java.util.ResourceBundle resourceBundle)
Deprecated.Creates a new HashMap using data copied from a ResourceBundle.- Parameters:
resourceBundle
- the resource bundle to convert, may not be null- Returns:
- the hashmap containing the data
- Throws:
java.lang.NullPointerException
- if the bundle is null
-
verbosePrint
public static void verbosePrint(java.io.PrintStream out, java.lang.Object label, java.util.Map map)
Deprecated.Prints the given map with nice line breaks.This method prints a nicely formatted String describing the Map. Each map entry will be printed with key and value. When the value is a Map, recursive behaviour occurs.
This method is NOT thread-safe in any special way. You must manually synchronize on either this class or the stream as required.
- Parameters:
out
- the stream to print to, must not be nulllabel
- The label to be used, may benull
. Ifnull
, the label is not output. It typically represents the name of the property in a bean or similar.map
- The map to print, may benull
. Ifnull
, the text 'null' is output.- Throws:
java.lang.NullPointerException
- if the stream isnull
-
debugPrint
public static void debugPrint(java.io.PrintStream out, java.lang.Object label, java.util.Map map)
Deprecated.Prints the given map with nice line breaks.This method prints a nicely formatted String describing the Map. Each map entry will be printed with key, value and value classname. When the value is a Map, recursive behaviour occurs.
This method is NOT thread-safe in any special way. You must manually synchronize on either this class or the stream as required.
- Parameters:
out
- the stream to print to, must not be nulllabel
- The label to be used, may benull
. Ifnull
, the label is not output. It typically represents the name of the property in a bean or similar.map
- The map to print, may benull
. Ifnull
, the text 'null' is output.- Throws:
java.lang.NullPointerException
- if the stream isnull
-
invertMap
public static java.util.Map invertMap(java.util.Map map)
Deprecated.Inverts the supplied map returning a new HashMap such that the keys of the input are swapped with the values.This operation assumes that the inverse mapping is well defined. If the input map had multiple entries with the same value mapped to different keys, the returned map will map one of those keys to the value, but the exact key which will be mapped is undefined.
- Parameters:
map
- the map to invert, may not be null- Returns:
- a new HashMap containing the inverted data
- Throws:
java.lang.NullPointerException
- if the map is null
-
safeAddToMap
public static void safeAddToMap(java.util.Map map, java.lang.Object key, java.lang.Object value) throws java.lang.NullPointerException
Deprecated.Protects against adding null values to a map.This method checks the value being added to the map, and if it is null it is replaced by an empty string.
This could be useful if the map does not accept null values, or for receiving data from a source that may provide null or empty string which should be held in the same way in the map.
Keys are not validated.
- Parameters:
map
- the map to add to, may not be nullkey
- the keyvalue
- the value, null converted to ""- Throws:
java.lang.NullPointerException
- if the map is null
-
putAll
public static java.util.Map putAll(java.util.Map map, java.lang.Object[] array)
Deprecated.Puts all the keys and values from the specified array into the map.This method is an alternative to the
Map.putAll(java.util.Map)
method and constructors. It allows you to build a map from an object array of various possible styles.If the first entry in the object array implements
Map.Entry
orKeyValue
then the key and value are added from that object. If the first entry in the object array is an object array itself, then it is assumed that index 0 in the sub-array is the key and index 1 is the value. Otherwise, the array is treated as keys and values in alternate indices.For example, to create a color map:
Map colorMap = MapUtils.putAll(new HashMap(), new String[][] { {"RED", "#FF0000"}, {"GREEN", "#00FF00"}, {"BLUE", "#0000FF"} });
or:Map colorMap = MapUtils.putAll(new HashMap(), new String[] { "RED", "#FF0000", "GREEN", "#00FF00", "BLUE", "#0000FF" });
or:Map colorMap = MapUtils.putAll(new HashMap(), new Map.Entry[] { new DefaultMapEntry("RED", "#FF0000"), new DefaultMapEntry("GREEN", "#00FF00"), new DefaultMapEntry("BLUE", "#0000FF") });
- Parameters:
map
- the map to populate, must not be nullarray
- an array to populate from, null ignored- Returns:
- the input map
- Throws:
java.lang.NullPointerException
- if map is nulljava.lang.IllegalArgumentException
- if sub-array or entry matching used and an entry is invalidjava.lang.ClassCastException
- if the array contents is mixed- Since:
- Commons Collections 3.2
-
isEmpty
public static boolean isEmpty(java.util.Map map)
Deprecated.Null-safe check if the specified map is empty.Null returns true.
- Parameters:
map
- the map to check, may be null- Returns:
- true if empty or null
- Since:
- Commons Collections 3.2
-
isNotEmpty
public static boolean isNotEmpty(java.util.Map map)
Deprecated.Null-safe check if the specified map is not empty.Null returns false.
- Parameters:
map
- the map to check, may be null- Returns:
- true if non-null and non-empty
- Since:
- Commons Collections 3.2
-
synchronizedMap
public static java.util.Map synchronizedMap(java.util.Map map)
Deprecated.Returns a synchronized map backed by the given map.You must manually synchronize on the returned buffer's iterator to avoid non-deterministic behavior:
Map m = MapUtils.synchronizedMap(myMap); Set s = m.keySet(); // outside synchronized block synchronized (m) { // synchronized on MAP! Iterator i = s.iterator(); while (i.hasNext()) { process (i.next()); } }
This method uses the implementation inCollections
.- Parameters:
map
- the map to synchronize, must not be null- Returns:
- a synchronized map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the map is null
-
unmodifiableMap
public static java.util.Map unmodifiableMap(java.util.Map map)
Deprecated.Returns an unmodifiable map backed by the given map.This method uses the implementation in the decorators subpackage.
- Parameters:
map
- the map to make unmodifiable, must not be null- Returns:
- an unmodifiable map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the map is null
-
predicatedMap
public static java.util.Map predicatedMap(java.util.Map map, Predicate keyPred, Predicate valuePred)
Deprecated.Returns a predicated (validating) map backed by the given map.Only objects that pass the tests in the given predicates can be added to the map. Trying to add an invalid object results in an IllegalArgumentException. Keys must pass the key predicate, values must pass the value predicate. It is important not to use the original map after invoking this method, as it is a backdoor for adding invalid objects.
- Parameters:
map
- the map to predicate, must not be nullkeyPred
- the predicate for keys, null means no checkvaluePred
- the predicate for values, null means no check- Returns:
- a predicated map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the Map is null
-
typedMap
public static java.util.Map typedMap(java.util.Map map, java.lang.Class keyType, java.lang.Class valueType)
Deprecated.Returns a typed map backed by the given map.Only keys and values of the specified types can be added to the map.
- Parameters:
map
- the map to limit to a specific type, must not be nullkeyType
- the type of keys which may be added to the map, must not be nullvalueType
- the type of values which may be added to the map, must not be null- Returns:
- a typed map backed by the specified map
- Throws:
java.lang.IllegalArgumentException
- if the Map or Class is null
-
transformedMap
public static java.util.Map transformedMap(java.util.Map map, Transformer keyTransformer, Transformer valueTransformer)
Deprecated.Returns a transformed map backed by the given map.This method returns a new map (decorating the specified map) that will transform any new entries added to it. Existing entries in the specified map will not be transformed. If you want that behaviour, see
TransformedMap.decorateTransform(java.util.Map, org.apache.commons.collections.Transformer, org.apache.commons.collections.Transformer)
.Each object is passed through the transformers as it is added to the Map. It is important not to use the original map after invoking this method, as it is a backdoor for adding untransformed objects.
If there are any elements already in the map being decorated, they are NOT transformed.
- Parameters:
map
- the map to transform, must not be null, typically emptykeyTransformer
- the transformer for the map keys, null means no transformationvalueTransformer
- the transformer for the map values, null means no transformation- Returns:
- a transformed map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the Map is null
-
fixedSizeMap
public static java.util.Map fixedSizeMap(java.util.Map map)
Deprecated.Returns a fixed-sized map backed by the given map. Elements may not be added or removed from the returned map, but existing elements can be changed (for instance, via theMap.put(Object,Object)
method).- Parameters:
map
- the map whose size to fix, must not be null- Returns:
- a fixed-size map backed by that map
- Throws:
java.lang.IllegalArgumentException
- if the Map is null
-
lazyMap
public static java.util.Map lazyMap(java.util.Map map, Factory factory)
Deprecated.Returns a "lazy" map whose values will be created on demand.When the key passed to the returned map's
Map.get(Object)
method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key.For instance:
Factory factory = new Factory() { public Object create() { return new Date(); } } Map lazyMap = MapUtils.lazyMap(new HashMap(), factory); Object obj = lazyMap.get("test");
After the above code is executed,obj
will contain a newDate
instance. Furthermore, thatDate
instance is the value for the"test"
key in the map.- Parameters:
map
- the map to make lazy, must not be nullfactory
- the factory for creating new objects, must not be null- Returns:
- a lazy map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the Map or Factory is null
-
lazyMap
public static java.util.Map lazyMap(java.util.Map map, Transformer transformerFactory)
Deprecated.Returns a "lazy" map whose values will be created on demand.When the key passed to the returned map's
Map.get(Object)
method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key. The factory is aTransformer
that will be passed the key which it must transform into the value.For instance:
Transformer factory = new Transformer() { public Object transform(Object mapKey) { return new File(mapKey); } } Map lazyMap = MapUtils.lazyMap(new HashMap(), factory); Object obj = lazyMap.get("C:/dev");
After the above code is executed,obj
will contain a newFile
instance for the C drive dev directory. Furthermore, thatFile
instance is the value for the"C:/dev"
key in the map.If a lazy map is wrapped by a synchronized map, the result is a simple synchronized cache. When an object is not is the cache, the cache itself calls back to the factory Transformer to populate itself, all within the same synchronized block.
- Parameters:
map
- the map to make lazy, must not be nulltransformerFactory
- the factory for creating new objects, must not be null- Returns:
- a lazy map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the Map or Transformer is null
-
orderedMap
public static java.util.Map orderedMap(java.util.Map map)
Deprecated.Returns a map that maintains the order of keys that are added backed by the given map.If a key is added twice, the order is determined by the first add. The order is observed through the keySet, values and entrySet.
- Parameters:
map
- the map to order, must not be null- Returns:
- an ordered map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the Map is null
-
multiValueMap
public static java.util.Map multiValueMap(java.util.Map map)
Deprecated.Creates a mult-value map backed by the given map which returns collections of type ArrayList.- Parameters:
map
- the map to decorate- Returns:
- a multi-value map backed by the given map which returns ArrayLists of values.
- Since:
- Commons Collections 3.2
- See Also:
MultiValueMap
-
multiValueMap
public static java.util.Map multiValueMap(java.util.Map map, java.lang.Class collectionClass)
Deprecated.Creates a multi-value map backed by the given map which returns collections of the specified type.- Parameters:
map
- the map to decoratecollectionClass
- the type of collections to return from the map (must contain public no-arg constructor and extend Collection).- Returns:
- a multi-value map backed by the given map which returns collections of the specified type
- Since:
- Commons Collections 3.2
- See Also:
MultiValueMap
-
multiValueMap
public static java.util.Map multiValueMap(java.util.Map map, Factory collectionFactory)
Deprecated.Creates a multi-value map backed by the given map which returns collections created by the specified collection factory.- Parameters:
map
- the map to decoratecollectionFactory
- a factor which creates collection objects- Returns:
- a multi-value map backed by the given map which returns collections created by the specified collection factory
- Since:
- Commons Collections 3.2
- See Also:
MultiValueMap
-
synchronizedSortedMap
public static java.util.Map synchronizedSortedMap(java.util.SortedMap map)
Deprecated.Returns a synchronized sorted map backed by the given sorted map.You must manually synchronize on the returned buffer's iterator to avoid non-deterministic behavior:
Map m = MapUtils.synchronizedSortedMap(myMap); Set s = m.keySet(); // outside synchronized block synchronized (m) { // synchronized on MAP! Iterator i = s.iterator(); while (i.hasNext()) { process (i.next()); } }
This method uses the implementation inCollections
.- Parameters:
map
- the map to synchronize, must not be null- Returns:
- a synchronized map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the map is null
-
unmodifiableSortedMap
public static java.util.Map unmodifiableSortedMap(java.util.SortedMap map)
Deprecated.Returns an unmodifiable sorted map backed by the given sorted map.This method uses the implementation in the decorators subpackage.
- Parameters:
map
- the sorted map to make unmodifiable, must not be null- Returns:
- an unmodifiable map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the map is null
-
predicatedSortedMap
public static java.util.SortedMap predicatedSortedMap(java.util.SortedMap map, Predicate keyPred, Predicate valuePred)
Deprecated.Returns a predicated (validating) sorted map backed by the given map.Only objects that pass the tests in the given predicates can be added to the map. Trying to add an invalid object results in an IllegalArgumentException. Keys must pass the key predicate, values must pass the value predicate. It is important not to use the original map after invoking this method, as it is a backdoor for adding invalid objects.
- Parameters:
map
- the map to predicate, must not be nullkeyPred
- the predicate for keys, null means no checkvaluePred
- the predicate for values, null means no check- Returns:
- a predicated map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the SortedMap is null
-
typedSortedMap
public static java.util.SortedMap typedSortedMap(java.util.SortedMap map, java.lang.Class keyType, java.lang.Class valueType)
Deprecated.Returns a typed sorted map backed by the given map.Only keys and values of the specified types can be added to the map.
- Parameters:
map
- the map to limit to a specific type, must not be nullkeyType
- the type of keys which may be added to the map, must not be nullvalueType
- the type of values which may be added to the map, must not be null- Returns:
- a typed map backed by the specified map
-
transformedSortedMap
public static java.util.SortedMap transformedSortedMap(java.util.SortedMap map, Transformer keyTransformer, Transformer valueTransformer)
Deprecated.Returns a transformed sorted map backed by the given map.This method returns a new sorted map (decorating the specified map) that will transform any new entries added to it. Existing entries in the specified map will not be transformed. If you want that behaviour, see
TransformedSortedMap.decorateTransform(java.util.SortedMap, org.apache.commons.collections.Transformer, org.apache.commons.collections.Transformer)
.Each object is passed through the transformers as it is added to the Map. It is important not to use the original map after invoking this method, as it is a backdoor for adding untransformed objects.
If there are any elements already in the map being decorated, they are NOT transformed.
- Parameters:
map
- the map to transform, must not be null, typically emptykeyTransformer
- the transformer for the map keys, null means no transformationvalueTransformer
- the transformer for the map values, null means no transformation- Returns:
- a transformed map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the SortedMap is null
-
fixedSizeSortedMap
public static java.util.SortedMap fixedSizeSortedMap(java.util.SortedMap map)
Deprecated.Returns a fixed-sized sorted map backed by the given sorted map. Elements may not be added or removed from the returned map, but existing elements can be changed (for instance, via theMap.put(Object,Object)
method).- Parameters:
map
- the map whose size to fix, must not be null- Returns:
- a fixed-size map backed by that map
- Throws:
java.lang.IllegalArgumentException
- if the SortedMap is null
-
lazySortedMap
public static java.util.SortedMap lazySortedMap(java.util.SortedMap map, Factory factory)
Deprecated.Returns a "lazy" sorted map whose values will be created on demand.When the key passed to the returned map's
Map.get(Object)
method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key.For instance:
Factory factory = new Factory() { public Object create() { return new Date(); } } SortedMap lazy = MapUtils.lazySortedMap(new TreeMap(), factory); Object obj = lazy.get("test");
After the above code is executed,obj
will contain a newDate
instance. Furthermore, thatDate
instance is the value for the"test"
key.- Parameters:
map
- the map to make lazy, must not be nullfactory
- the factory for creating new objects, must not be null- Returns:
- a lazy map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the SortedMap or Factory is null
-
lazySortedMap
public static java.util.SortedMap lazySortedMap(java.util.SortedMap map, Transformer transformerFactory)
Deprecated.Returns a "lazy" sorted map whose values will be created on demand.When the key passed to the returned map's
Map.get(Object)
method is not present in the map, then the factory will be used to create a new object and that object will become the value associated with that key. The factory is aTransformer
that will be passed the key which it must transform into the value.For instance:
Transformer factory = new Transformer() { public Object transform(Object mapKey) { return new File(mapKey); } } SortedMap lazy = MapUtils.lazySortedMap(new TreeMap(), factory); Object obj = lazy.get("C:/dev");
After the above code is executed,obj
will contain a newFile
instance for the C drive dev directory. Furthermore, thatFile
instance is the value for the"C:/dev"
key in the map.If a lazy map is wrapped by a synchronized map, the result is a simple synchronized cache. When an object is not is the cache, the cache itself calls back to the factory Transformer to populate itself, all within the same synchronized block.
- Parameters:
map
- the map to make lazy, must not be nulltransformerFactory
- the factory for creating new objects, must not be null- Returns:
- a lazy map backed by the given map
- Throws:
java.lang.IllegalArgumentException
- if the Map or Transformer is null
-
-