public class MapUtils extends Object
java.util.HashMap
in the
following manner:
key1=value1
array[0]=http://get.me.1
array[1]=http://get.me.2
key2=value2
hrefs[0]=http://href.1
hrefs[1]=http://href.2Modifier and Type | Field and Description |
---|---|
static String |
CHAR_BRACKET_CLOSE |
static String |
CHAR_BRACKET_OPEN |
static String |
CHAR_EQUAL_SIGN |
static String |
CR_LF |
static String |
CR_LF_SUBST |
static int |
INVALID_INDEX |
static String |
LF |
Constructor and Description |
---|
MapUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
getBoolDef(Map<String,?> params,
String paramName,
boolean defaultValue)
Get boolean value as a parameter from the map, if the key is not found
default value is returned.
|
static DifferenceMap |
getDifference(Iterator<? extends String> keysIterator,
Map<String,?> mapOld,
Map<String,?> mapNew)
Construct difference map from the 2 selected maps of values and
a list of keys that should be checked.
|
static DifferenceMap |
getDifference(List<? extends String> keysList,
Map<String,?> mapOld,
Map<String,?> mapNew)
Construct difference map from the 2 selected maps of values and
a list of keys that should be checked.
|
static int |
getIntDef(Map<String,?> params,
String paramName,
int defaultValue)
Get integer value as a parameter from the map, if the key is not found
default value is returned.
|
static Integer |
getInteger(Map<String,?> params,
String paramName)
Return
java.lang.Integer as a key value from the given map. |
static Integer |
getIntegerDef(Map<String,?> params,
String paramName,
Integer defaultValue)
Return
java.lang.Integer as a key value from the given map. |
static Long |
getLong(Map<String,?> params,
String paramName)
Return
java.lang.Long as a key value from the given map. |
static Long |
getLongDef(Map<String,?> params,
String paramName,
Long defaultValue)
Return
java.lang.Long as a key value from the given map. |
static <T> Map<String,T> |
getPrefixedKeys(Map<String,T> params,
String keysPrefix)
Returns sub-map from the given one.
|
static String |
getStringDef(Map<String,?> params,
String paramName,
String defaultValue)
Return
java.lang.String as a key value from the given map. |
static <T> Map<String,T> |
getSubMapForKeys(String[] keys,
Map<String,T> map,
boolean removeFromOriginalMap)
Returns sub-map from the given one.
|
static <T> Map<String,T> |
getSubMapForKeys(String[] keys,
Map<String,T> map,
boolean removeFromOriginalMap,
boolean acceptNullValue) |
static Map<String,Object> |
getSubMapForPrefixedKeys(String keyPrefix,
Map<String,?> map,
boolean removeFromOriginalMap)
Returns sub-map from the given one.
|
static Map<String,Object> |
loadMap_Old(Reader reader)
Loads and creates new
java.util.Map instance of the container
from specified reader |
static Map<String,Object> |
loadMap(Reader reader)
Loads and creates new
java.util.Map instance of the container
from specified reader |
static Map<String,Object> |
loadMap(String s) |
static void |
saveMap_Old(Writer writer,
Map<String,?> map)
Saves
java.util.Map instance to the specified writer |
static String |
saveMap(Map<String,?> map) |
static void |
saveMap(Writer writer,
Map<String,?> map) |
public static final String CHAR_BRACKET_OPEN
public static final String CHAR_BRACKET_CLOSE
public static final String CHAR_EQUAL_SIGN
public static final int INVALID_INDEX
public static final String CR_LF_SUBST
public static final String CR_LF
public static final String LF
public static void saveMap_Old(Writer writer, Map<String,?> map) throws IOException
java.util.Map
instance to the specified writerwriter
- Destination java.io.Writer
instance as a destinationmap
- Instance of the map to store in the passed writerIOException
public static Map<String,Object> loadMap_Old(Reader reader) throws IOException
java.util.Map
instance of the container
from specified readerIOException
public static Map<String,Object> loadMap(String s) throws IOException
IOException
public static Map<String,Object> loadMap(Reader reader) throws IOException
java.util.Map
instance of the container
from specified readerIOException
public static String saveMap(Map<String,?> map) throws IOException
IOException
public static void saveMap(Writer writer, Map<String,?> map) throws IOException
IOException
public static DifferenceMap getDifference(List<? extends String> keysList, Map<String,?> mapOld, Map<String,?> mapNew)
diffMap[i] = new DifferenceEntry(keysList[i], oldValues[keysList[i]], newValues[keysList[i]]);
keysList
- List of keys to use querying old and new valuesmapOld
- Map instance containing old valuesmapNew
- Map instance containing new valuespublic static DifferenceMap getDifference(Iterator<? extends String> keysIterator, Map<String,?> mapOld, Map<String,?> mapNew)
diffMap[i] = new DifferenceEntry(keysIterator[i], oldValues[keysIterator[i]],
newValues[keysIterator[i]]);
keysIterator
- List of keys to use querying old and new valuesmapOld
- Map instance containing old valuesmapNew
- Map instance containing new valuespublic static int getIntDef(Map<String,?> params, String paramName, int defaultValue)
params
- Some map instance containing parameter value we are interested inparamName
- Name of the requested parameter in the mapdefaultValue
- Default integer value that will be taken if specified parameter
name was not found.public static boolean getBoolDef(Map<String,?> params, String paramName, boolean defaultValue)
params
- Some map instance containing parameter value we are interested inparamName
- Name of the requested parameter in the mapdefaultValue
- Default boolean value that will be taken if specified parameter
name was not found.public static Integer getIntegerDef(Map<String,?> params, String paramName, Integer defaultValue)
java.lang.Integer
as a key value from the given map.
If key is not found default value is returned. If parameter value is string -
the string is converted to the integer.params
- Some map instance containing parameter value we are interested inparamName
- Name of the requested parameter in the mapdefaultValue
- Default integer value that will be taken if specified parameter
name was not found.public static Integer getInteger(Map<String,?> params, String paramName)
java.lang.Integer
as a key value from the given map.
If key is not found null
is returnedparams
- Some map instance containing parameter value we are interested inparamName
- Name of the requested parameter in the mappublic static Long getLongDef(Map<String,?> params, String paramName, Long defaultValue)
java.lang.Long
as a key value from the given map.
If key is not found default value is returned. If parameter value is string -
the string is converted to the integer.params
- Some map instance containing parameter value we are interested inparamName
- Name of the requested parameter in the mapdefaultValue
- Default long value that will be taken if specified parameter
name was not found.public static Long getLong(Map<String,?> params, String paramName)
java.lang.Long
as a key value from the given map.
If key is not found null
is returnedparams
- Some map instance containing parameter value we are interested inparamName
- Name of the requested parameter in the mappublic static String getStringDef(Map<String,?> params, String paramName, String defaultValue)
java.lang.String
as a key value from the given map.
If key is not found default value is returnedparams
- Some map instance containing parameter value we are interested inparamName
- Name of the requested parameter in the mapdefaultValue
- Default string value to be taken if specified parameter doesn't existpublic static <T> Map<String,T> getPrefixedKeys(Map<String,T> params, String keysPrefix)
Map[0] -> key[0] = log_size; value[0] = 10 Map[1] -> key[1] = another_key_1; value[1] = 20 Map[2] -> key[2] = log_file; value[2] = Drive:/Folder ResultMap result = getPrefixedKeys(Map, "log_"); result.key[0] -> log_size result.key[1] -> log_fileSuitable for request parameters parsing. IMPORTANT: Map keys should be strings.
T
- params
- Map of the parameter valueskeysPrefix
- Prefix of the map keys to use to identify the keys to getpublic static <T> Map<String,T> getSubMapForKeys(String[] keys, Map<String,T> map, boolean removeFromOriginalMap)
T
- keys
- the list of keys that should be extractedmap
- Map of the property valuesremoveFromOriginalMap
- whether or not to remove extracted entries from the original mappublic static <T> Map<String,T> getSubMapForKeys(String[] keys, Map<String,T> map, boolean removeFromOriginalMap, boolean acceptNullValue)
public static Map<String,Object> getSubMapForPrefixedKeys(String keyPrefix, Map<String,?> map, boolean removeFromOriginalMap)
keyPrefix
- the prefix of keys that should be extractedmap
- Map of the property valuesremoveFromOriginalMap
- whether or not to remove extracted entries from the original map