Package com.webmethods.rtl.util.obj
Class MapUtils
java.lang.Object
com.webmethods.rtl.util.obj.MapUtils
Should be able to save/load
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.2-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
Construct difference map from the 2 selected maps of values and a list of keys that should be checked.static DifferenceMap
Construct difference map from the 2 selected maps of values and a list of keys that should be checked.static int
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) Returnjava.lang.Integer
as a key value from the given map.static Integer
getIntegerDef
(Map<String, ?> params, String paramName, Integer defaultValue) Returnjava.lang.Integer
as a key value from the given map.static Long
Returnjava.lang.Long
as a key value from the given map.static Long
getLongDef
(Map<String, ?> params, String paramName, Long defaultValue) Returnjava.lang.Long
as a key value from the given map.getPrefixedKeys
(Map<String, T> params, String keysPrefix) Returns sub-map from the given one.static String
getStringDef
(Map<String, ?> params, String paramName, String defaultValue) Returnjava.lang.String
as a key value from the given map.getSubMapForKeys
(String[] keys, Map<String, T> map, boolean removeFromOriginalMap) Returns sub-map from the given one.getSubMapForKeys
(String[] keys, Map<String, T> map, boolean removeFromOriginalMap, boolean acceptNullValue) getSubMapForPrefixedKeys
(String keyPrefix, Map<String, ?> map, boolean removeFromOriginalMap) Returns sub-map from the given one.Loads and creates newjava.util.Map
instance of the container from specified readerloadMap_Old
(Reader reader) Loads and creates newjava.util.Map
instance of the container from specified readerstatic void
static String
static void
saveMap_Old
(Writer writer, Map<String, ?> map) Savesjava.util.Map
instance to the specified writer
-
Field Details
-
CHAR_BRACKET_OPEN
- See Also:
-
CHAR_BRACKET_CLOSE
- See Also:
-
CHAR_EQUAL_SIGN
- See Also:
-
INVALID_INDEX
public static final int INVALID_INDEX- See Also:
-
CR_LF_SUBST
- See Also:
-
CR_LF
- See Also:
-
LF
- See Also:
-
-
Constructor Details
-
MapUtils
public MapUtils()
-
-
Method Details
-
saveMap_Old
Savesjava.util.Map
instance to the specified writer- Parameters:
writer
- Destinationjava.io.Writer
instance as a destinationmap
- Instance of the map to store in the passed writer- Throws:
IOException
-
loadMap_Old
Loads and creates newjava.util.Map
instance of the container from specified reader- Throws:
IOException
-
loadMap
- Throws:
IOException
-
loadMap
Loads and creates newjava.util.Map
instance of the container from specified reader- Throws:
IOException
-
saveMap
- Throws:
IOException
-
saveMap
- Throws:
IOException
-
getDifference
public 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. In pseudo-code it will look something like thisdiffMap[i] = new DifferenceEntry(keysList[i], oldValues[keysList[i]], newValues[keysList[i]]);
- Parameters:
keysList
- List of keys to use querying old and new valuesmapOld
- Map instance containing old valuesmapNew
- Map instance containing new values- Returns:
- Difference map on the base of the common key values inside the old and new maps
-
getDifference
public 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. In pseudo-code it will look something like thisdiffMap[i] = new DifferenceEntry(keysIterator[i], oldValues[keysIterator[i]], newValues[keysIterator[i]]);
- Parameters:
keysIterator
- List of keys to use querying old and new valuesmapOld
- Map instance containing old valuesmapNew
- Map instance containing new values- Returns:
- Creates difference map on the base of the common key values inside old and
-
getIntDef
Get integer value as a parameter from the map, if the key is not found default value is returned. If parameter value is string - the string is converted to the integer.- Parameters:
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.- Returns:
- Integer value for the specified parameter
-
getBoolDef
Get boolean value as a parameter from the map, if the key is not found default value is returned. If parameter value is string - the string is converted to the boolean.- Parameters:
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.- Returns:
- boolean value for the specified parameter
-
getIntegerDef
Returnjava.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.- Parameters:
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.- Returns:
- Integer value for the specified parameter
-
getInteger
Returnjava.lang.Integer
as a key value from the given map. If key is not foundnull
is returned- Parameters:
params
- Some map instance containing parameter value we are interested inparamName
- Name of the requested parameter in the map- Returns:
- Integer parameter value or null if none found.
-
getLongDef
Returnjava.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.- Parameters:
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.- Returns:
- Long value for the specified parameter
-
getLong
Returnjava.lang.Long
as a key value from the given map. If key is not foundnull
is returned- Parameters:
params
- Some map instance containing parameter value we are interested inparamName
- Name of the requested parameter in the map- Returns:
- Long parameter value or null if none found.
-
getStringDef
Returnjava.lang.String
as a key value from the given map. If key is not found default value is returned- Parameters:
params
- 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 exist- Returns:
- String value of the specified parameter
-
getPrefixedKeys
Returns sub-map from the given one. Only keys which start with the specified prefix are extracted. In pseudo codeMap[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_file
Suitable for request parameters parsing. IMPORTANT: Map keys should be strings.- Type Parameters:
T
-- Parameters:
params
- Map of the parameter valueskeysPrefix
- Prefix of the map keys to use to identify the keys to get- Returns:
- Map that contains only items that starts with the specified key prefix
-
getSubMapForKeys
public static <T> Map<String,T> getSubMapForKeys(String[] keys, Map<String, T> map, boolean removeFromOriginalMap) Returns sub-map from the given one. Only keys specified by the keys parameter go into the new map. Optionally, these keys may be removed from the original map Suitable for request parameters/properties parsing. IMPORTANT: Map keys should be strings.- Type Parameters:
T
-- Parameters:
keys
- the list of keys that should be extractedmap
- Map of the property valuesremoveFromOriginalMap
- whether or not to remove extracted entries from the original map- Returns:
- Map that contains only items with keys specified
-
getSubMapForKeys
-
getSubMapForPrefixedKeys
public static Map<String,Object> getSubMapForPrefixedKeys(String keyPrefix, Map<String, ?> map, boolean removeFromOriginalMap) Returns sub-map from the given one. Only keys that start with the specified prefix go into the new map. Optionally, these keys may be removed from the original map Suitable for request parameters/properties parsing. IMPORTANT: Map keys should be strings.- Parameters:
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- Returns:
- Map that contains only items with keys specified
-