code: public <K, V> String replace(String source,
                                   Map<K, V> patternReplacements) {
          if (source == null) {
              return null;
          }
  
          int mapSize = patternReplacements.size();
          String[] patterns = new String[mapSize];
          String[] replacements = new String[mapSize];
  
          Iterator<Map.Entry<K, V>> it =
              patternReplacements.entrySet().iterator();
  
          for (int i=0; it.hasNext(); i++) {
              Map.Entry<?, ?> entry = it.next();
              
              Object key = entry.getKey(), value = entry.getValue();
              patterns[i] = (key == null ? null : key.toString());
              replacements[i] = (value == null ? null : value.toString());
          }
  
          return StringReplacer.replace(source, patterns, replacements);
      }
docs: Applies string replacements using the pattern-replacement pairs provided
  by the given map (associative array). The longest matching pattern is
  used for selecting an appropriate replacement.
  
  @param source the source string
  @param patternReplacements pattern-replacement pairs