|
@@ -52,6 +52,38 @@ public class StringUtil {
|
|
|
return null == deptCodes ? new String[]{} : deptCodes.substring(1, deptCodes.length() - 1).replaceAll("\"", "").split(",");
|
|
|
}
|
|
|
|
|
|
+ public static String desensitizeName(String name) {
|
|
|
+ if (isBlank(name) || name.length() == 1) {
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+ if (!name.contains(" ")) {
|
|
|
+ return executeDesensitize(name);
|
|
|
+ }
|
|
|
+ String[] arr = name.split(" ");
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
+ for (String part : arr) {
|
|
|
+ result.append(" ").append(executeDesensitize(part));
|
|
|
+ }
|
|
|
+ return result.substring(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String executeDesensitize(String str) {
|
|
|
+ if (str.length() == 2) {
|
|
|
+ return str.charAt(0) + "*";
|
|
|
+ }
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ builder.append(str.charAt(0));
|
|
|
+ for (int i = 1; i < str.length() - 1; i++) {
|
|
|
+ if (str.charAt(i) == ' ') {
|
|
|
+ builder.append(" ");
|
|
|
+ } else {
|
|
|
+ builder.append("*");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ builder.append(str.charAt(str.length() - 1));
|
|
|
+ return builder.toString();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 把原始字符串分割成指定长度的字符串列表
|
|
|
*
|
|
@@ -147,7 +179,7 @@ public class StringUtil {
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
- private static Pattern linePattern = Pattern.compile("_(\\w)");
|
|
|
+ private static final Pattern linePattern = Pattern.compile("_(\\w)");
|
|
|
|
|
|
|
|
|
public static String lineToHump(String str) {
|
|
@@ -270,23 +302,5 @@ public class StringUtil {
|
|
|
return c;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("id", "123123123");
|
|
|
- map.put("name", "如花");
|
|
|
- map.put("age", "18");
|
|
|
- String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
|
|
- "<tx>\n" +
|
|
|
- " <txbody>\n" +
|
|
|
- " <id>${id}</id>\n" +
|
|
|
- " <name>${name}</name>\n" +
|
|
|
- " <age>${age}</age>\n" +
|
|
|
- " </txbody>\n" +
|
|
|
- "</tx>";
|
|
|
- String nxmlContent = replaceElementValue(content, map);
|
|
|
- System.out.println(nxmlContent);
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|