This commit is contained in:
Looly
2022-05-05 11:32:54 +08:00
parent e05a3b19e0
commit 34704bd326
3 changed files with 32 additions and 22 deletions

View File

@@ -194,7 +194,7 @@ public final class SensitiveUtil {
* @return 敏感词过滤处理后的bean对象
*/
public static <T> T sensitiveFilter(T bean, boolean isGreedMatch, SensitiveProcessor sensitiveProcessor) {
String jsonText = JSONUtil.toJsonStr(bean);
final String jsonText = JSONUtil.toJsonStr(bean);
@SuppressWarnings("unchecked") final Class<T> c = (Class<T>) bean.getClass();
return JSONUtil.toBean(sensitiveFilter(jsonText, isGreedMatch, sensitiveProcessor), c);
}
@@ -224,7 +224,7 @@ public final class SensitiveUtil {
}
//敏感词过滤场景下,不需要密集匹配
List<FoundWord> foundWordList = getFoundAllSensitive(text, true, isGreedMatch);
final List<FoundWord> foundWordList = getFoundAllSensitive(text, true, isGreedMatch);
if (CollUtil.isEmpty(foundWordList)) {
return text;
}
@@ -233,10 +233,10 @@ public final class SensitiveUtil {
final Map<Integer, FoundWord> foundWordMap = new HashMap<>(foundWordList.size(), 1);
foundWordList.forEach(foundWord -> foundWordMap.put(foundWord.getStartIndex(), foundWord));
int length = text.length();
StringBuilder textStringBuilder = new StringBuilder();
final int length = text.length();
final StringBuilder textStringBuilder = new StringBuilder();
for (int i = 0; i < length; i++) {
FoundWord fw = foundWordMap.get(i);
final FoundWord fw = foundWordMap.get(i);
if (fw != null) {
textStringBuilder.append(sensitiveProcessor.process(fw));
i = fw.getEndIndex();