Class MapUtils

java.lang.Object
com.webmethods.rtl.util.obj.MapUtils

public class MapUtils extends Object
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 Details

  • Constructor Details

    • MapUtils

      public MapUtils()
  • Method Details

    • saveMap_Old

      public static void saveMap_Old(Writer writer, Map<String,?> map) throws IOException
      Saves java.util.Map instance to the specified writer
      Parameters:
      writer - Destination java.io.Writer instance as a destination
      map - Instance of the map to store in the passed writer
      Throws:
      IOException
    • loadMap_Old

      public static Map<String,Object> loadMap_Old(Reader reader) throws IOException
      Loads and creates new java.util.Map instance of the container from specified reader
      Throws:
      IOException
    • loadMap

      public static Map<String,Object> loadMap(String s) throws IOException
      Throws:
      IOException
    • loadMap

      public static Map<String,Object> loadMap(Reader reader) throws IOException
      Loads and creates new java.util.Map instance of the container from specified reader
      Throws:
      IOException
    • saveMap

      public static String saveMap(Map<String,?> map) throws IOException
      Throws:
      IOException
    • saveMap

      public static void saveMap(Writer writer, Map<String,?> map) throws IOException
      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 this diffMap[i] = new DifferenceEntry(keysList[i], oldValues[keysList[i]], newValues[keysList[i]]);
      Parameters:
      keysList - List of keys to use querying old and new values
      mapOld - Map instance containing old values
      mapNew - 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 this diffMap[i] = new DifferenceEntry(keysIterator[i], oldValues[keysIterator[i]], newValues[keysIterator[i]]);
      Parameters:
      keysIterator - List of keys to use querying old and new values
      mapOld - Map instance containing old values
      mapNew - Map instance containing new values
      Returns:
      Creates difference map on the base of the common key values inside old and
    • getIntDef

      public 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. If parameter value is string - the string is converted to the integer.
      Parameters:
      params - Some map instance containing parameter value we are interested in
      paramName - Name of the requested parameter in the map
      defaultValue - Default integer value that will be taken if specified parameter name was not found.
      Returns:
      Integer value for the specified parameter
    • getBoolDef

      public 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. If parameter value is string - the string is converted to the boolean.
      Parameters:
      params - Some map instance containing parameter value we are interested in
      paramName - Name of the requested parameter in the map
      defaultValue - Default boolean value that will be taken if specified parameter name was not found.
      Returns:
      boolean value for the specified parameter
    • getIntegerDef

      public static Integer getIntegerDef(Map<String,?> params, String paramName, Integer defaultValue)
      Return 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.
      Parameters:
      params - Some map instance containing parameter value we are interested in
      paramName - Name of the requested parameter in the map
      defaultValue - Default integer value that will be taken if specified parameter name was not found.
      Returns:
      Integer value for the specified parameter
    • getInteger

      public static Integer getInteger(Map<String,?> params, String paramName)
      Return java.lang.Integer as a key value from the given map. If key is not found null is returned
      Parameters:
      params - Some map instance containing parameter value we are interested in
      paramName - Name of the requested parameter in the map
      Returns:
      Integer parameter value or null if none found.
    • getLongDef

      public static Long getLongDef(Map<String,?> params, String paramName, Long defaultValue)
      Return 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.
      Parameters:
      params - Some map instance containing parameter value we are interested in
      paramName - Name of the requested parameter in the map
      defaultValue - Default long value that will be taken if specified parameter name was not found.
      Returns:
      Long value for the specified parameter
    • getLong

      public static Long getLong(Map<String,?> params, String paramName)
      Return java.lang.Long as a key value from the given map. If key is not found null is returned
      Parameters:
      params - Some map instance containing parameter value we are interested in
      paramName - Name of the requested parameter in the map
      Returns:
      Long parameter value or null if none found.
    • getStringDef

      public static String getStringDef(Map<String,?> params, String paramName, String defaultValue)
      Return java.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 in
      paramName - Name of the requested parameter in the map
      defaultValue - Default string value to be taken if specified parameter doesn't exist
      Returns:
      String value of the specified parameter
    • getPrefixedKeys

      public static <T> Map<String,T> getPrefixedKeys(Map<String,T> params, String keysPrefix)
      Returns sub-map from the given one. Only keys which start with the specified prefix are extracted. In pseudo code
       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_file
       
      Suitable for request parameters parsing. IMPORTANT: Map keys should be strings.
      Type Parameters:
      T -
      Parameters:
      params - Map of the parameter values
      keysPrefix - 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 extracted
      map - Map of the property values
      removeFromOriginalMap - whether or not to remove extracted entries from the original map
      Returns:
      Map that contains only items with keys specified
    • getSubMapForKeys

      public static <T> Map<String,T> getSubMapForKeys(String[] keys, Map<String,T> map, boolean removeFromOriginalMap, boolean acceptNullValue)
    • 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 extracted
      map - Map of the property values
      removeFromOriginalMap - whether or not to remove extracted entries from the original map
      Returns:
      Map that contains only items with keys specified