Java Map Replace replace(String orign, Map replaceStringMap)

Here you can find the source of replace(String orign, Map replaceStringMap)

Description

replace class Name by class full Name for example change List to java.util.List if class Name contains .

License

Apache License

Declaration

private static String replace(String orign, Map replaceStringMap) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Map;

public class Main {
    /**/*from  w  w w .  java2  s  .  c o m*/
     * replace class Name by class full Name 
     * for example change List to java.util.List
     * if class Name contains . then get the String that before the first "." to be replaced 
     * for example "List.invoke" get "List" string and replace it with java.util.List
     * if current string is "java.util.List" then get "java" string and try to replace it
     * so in most case it will be OK.
     * but if there existed a key with "java" in the classTypes Map, then "java" string also will be replaced. so it's a bug
     */
    private static String replace(String orign, Map replaceStringMap) {

        int index = orign.indexOf(".");
        String checkName = orign;
        if (index != -1) {
            checkName = orign.substring(0, index);
        }
        String result = orign;
        if (replaceStringMap.get(checkName) != null) {
            String classFullName = ((String) replaceStringMap.get(checkName));
            result = classFullName + (index > 0 ? orign.substring(index) : orign.substring(checkName.length()));
        }

        return result;
    }
}

Related

  1. replace(Map map, String content)
  2. replace(Map map, String text)
  3. replace(String originalCommand, Map vars)
  4. replace(String s, Map map)
  5. replace(String src, String prefix, String suffix, Map props)
  6. replace(String str, Map values)
  7. replace(String string, Map values)