|
@@ -26,19 +26,14 @@ public abstract class AbstractSliderDesensitizationHandler<T extends Annotation>
|
|
int suffixKeep = getSuffixKeep(annotation);
|
|
int suffixKeep = getSuffixKeep(annotation);
|
|
String replacer = getReplacer(annotation);
|
|
String replacer = getReplacer(annotation);
|
|
int length = origin.length();
|
|
int length = origin.length();
|
|
|
|
+ int interval = length - prefixKeep - suffixKeep;
|
|
|
|
|
|
- // 情况一:原始字符串长度小于等于保留长度,则原始字符串全部替换
|
|
|
|
- if (prefixKeep >= length || suffixKeep >= length) {
|
|
|
|
- return buildReplacerByLength(replacer, length);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 情况二:原始字符串长度小于等于前后缀保留字符串长度,则原始字符串全部替换
|
|
|
|
- if ((prefixKeep + suffixKeep) >= length) {
|
|
|
|
|
|
+ // 情况一:原始字符串长度小于等于前后缀保留字符串长度,则原始字符串全部替换
|
|
|
|
+ if (interval <= 0) {
|
|
return buildReplacerByLength(replacer, length);
|
|
return buildReplacerByLength(replacer, length);
|
|
}
|
|
}
|
|
|
|
|
|
- // 情况三:原始字符串长度大于前后缀保留字符串长度,则替换中间字符串
|
|
|
|
- int interval = length - prefixKeep - suffixKeep;
|
|
|
|
|
|
+ // 情况二:原始字符串长度大于前后缀保留字符串长度,则替换中间字符串
|
|
return origin.substring(0, prefixKeep) +
|
|
return origin.substring(0, prefixKeep) +
|
|
buildReplacerByLength(replacer, interval) +
|
|
buildReplacerByLength(replacer, interval) +
|
|
origin.substring(prefixKeep + interval);
|
|
origin.substring(prefixKeep + interval);
|
|
@@ -52,11 +47,7 @@ public abstract class AbstractSliderDesensitizationHandler<T extends Annotation>
|
|
* @return 构建后的替换符
|
|
* @return 构建后的替换符
|
|
*/
|
|
*/
|
|
private String buildReplacerByLength(String replacer, int length) {
|
|
private String buildReplacerByLength(String replacer, int length) {
|
|
- StringBuilder builder = new StringBuilder();
|
|
|
|
- for (int i = 0; i < length; i++) {
|
|
|
|
- builder.append(replacer);
|
|
|
|
- }
|
|
|
|
- return builder.toString();
|
|
|
|
|
|
+ return replacer.repeat(length);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|