public final class SensitiveUtil extends Object
Modifier and Type | Field and Description |
---|---|
static char |
DEFAULT_SEPARATOR |
Constructor and Description |
---|
SensitiveUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
containsSensitive(Object obj)
是否包含敏感词
|
static boolean |
containsSensitive(String text)
是否包含敏感词
|
static List<String> |
getFindedAllSensitive(Object bean)
Deprecated.
|
static List<String> |
getFindedAllSensitive(Object bean,
boolean isDensityMatch,
boolean isGreedMatch)
Deprecated.
|
static List<String> |
getFindedAllSensitive(String text)
Deprecated.
|
static List<String> |
getFindedAllSensitive(String text,
boolean isDensityMatch,
boolean isGreedMatch)
Deprecated.
|
static String |
getFindedFirstSensitive(Object obj)
Deprecated.
|
static String |
getFindedFirstSensitive(String text)
Deprecated.
|
static List<FoundWord> |
getFoundAllSensitive(Object bean)
查找敏感词,返回找到的所有敏感词
|
static List<FoundWord> |
getFoundAllSensitive(Object bean,
boolean isDensityMatch,
boolean isGreedMatch)
查找敏感词,返回找到的所有敏感词
密集匹配原则:假如关键词有 ab,b,文本是abab,将匹配 [ab,b,ab] 贪婪匹配(最长匹配)原则:假如关键字a,ab,最长匹配将匹配[a, ab] |
static List<FoundWord> |
getFoundAllSensitive(String text)
查找敏感词,返回找到的所有敏感词
|
static List<FoundWord> |
getFoundAllSensitive(String text,
boolean isDensityMatch,
boolean isGreedMatch)
查找敏感词,返回找到的所有敏感词
密集匹配原则:假如关键词有 ab,b,文本是abab,将匹配 [ab,b,ab] 贪婪匹配(最长匹配)原则:假如关键字a,ab,最长匹配将匹配[a, ab] |
static FoundWord |
getFoundFirstSensitive(Object obj)
查找敏感词,返回找到的第一个敏感词
|
static FoundWord |
getFoundFirstSensitive(String text)
查找敏感词,返回找到的第一个敏感词
|
static void |
init(Collection<String> sensitiveWords)
初始化敏感词树
|
static void |
init(Collection<String> sensitiveWords,
boolean isAsync)
初始化敏感词树
|
static void |
init(String sensitiveWords,
boolean isAsync)
初始化敏感词树,使用逗号分隔每个单词
|
static void |
init(String sensitiveWords,
char separator,
boolean isAsync)
初始化敏感词树
|
static boolean |
isInited() |
static String |
sensitiveFilter(String text,
boolean isGreedMatch,
SensitiveProcessor sensitiveProcessor)
处理过滤文本中的敏感词,默认替换成*
|
static <T> T |
sensitiveFilter(T bean,
boolean isGreedMatch,
SensitiveProcessor sensitiveProcessor)
敏感词过滤
|
static void |
setCharFilter(Filter<Character> charFilter)
设置字符过滤规则,通过定义字符串过滤规则,过滤不需要的字符
当accept为false时,此字符不参与匹配 |
public static final char DEFAULT_SEPARATOR
public static boolean isInited()
public static void init(Collection<String> sensitiveWords, boolean isAsync)
isAsync
- 是否异步初始化sensitiveWords
- 敏感词列表public static void init(Collection<String> sensitiveWords)
sensitiveWords
- 敏感词列表public static void init(String sensitiveWords, char separator, boolean isAsync)
sensitiveWords
- 敏感词列表组成的字符串isAsync
- 是否异步初始化separator
- 分隔符public static void init(String sensitiveWords, boolean isAsync)
sensitiveWords
- 敏感词列表组成的字符串isAsync
- 是否异步初始化public static void setCharFilter(Filter<Character> charFilter)
charFilter
- 过滤函数public static boolean containsSensitive(String text)
text
- 文本public static boolean containsSensitive(Object obj)
obj
- bean,会被转为JSON字符串@Deprecated public static String getFindedFirstSensitive(String text)
getFoundFirstSensitive(String)
text
- 文本public static FoundWord getFoundFirstSensitive(String text)
text
- 文本@Deprecated public static String getFindedFirstSensitive(Object obj)
getFoundFirstSensitive(Object)
obj
- bean,会被转为JSON字符串public static FoundWord getFoundFirstSensitive(Object obj)
obj
- bean,会被转为JSON字符串@Deprecated public static List<String> getFindedAllSensitive(String text)
getFoundAllSensitive(String)
text
- 文本public static List<FoundWord> getFoundAllSensitive(String text)
text
- 文本@Deprecated public static List<String> getFindedAllSensitive(String text, boolean isDensityMatch, boolean isGreedMatch)
getFoundAllSensitive(String, boolean, boolean)
text
- 文本isDensityMatch
- 是否使用密集匹配原则isGreedMatch
- 是否使用贪婪匹配(最长匹配)原则public static List<FoundWord> getFoundAllSensitive(String text, boolean isDensityMatch, boolean isGreedMatch)
text
- 文本isDensityMatch
- 是否使用密集匹配原则isGreedMatch
- 是否使用贪婪匹配(最长匹配)原则@Deprecated public static List<String> getFindedAllSensitive(Object bean)
getFoundAllSensitive(Object)
bean
- 对象,会被转为JSONpublic static List<FoundWord> getFoundAllSensitive(Object bean)
bean
- 对象,会被转为JSON@Deprecated public static List<String> getFindedAllSensitive(Object bean, boolean isDensityMatch, boolean isGreedMatch)
getFoundAllSensitive(Object, boolean, boolean)
bean
- 对象,会被转为JSONisDensityMatch
- 是否使用密集匹配原则isGreedMatch
- 是否使用贪婪匹配(最长匹配)原则public static List<FoundWord> getFoundAllSensitive(Object bean, boolean isDensityMatch, boolean isGreedMatch)
bean
- 对象,会被转为JSONisDensityMatch
- 是否使用密集匹配原则isGreedMatch
- 是否使用贪婪匹配(最长匹配)原则public static <T> T sensitiveFilter(T bean, boolean isGreedMatch, SensitiveProcessor sensitiveProcessor)
T
- bean的class类型bean
- 对象,会被转为JSONisGreedMatch
- 贪婪匹配(最长匹配)原则:假如关键字a,ab,最长匹配将匹配[a, ab]sensitiveProcessor
- 敏感词处理器,默认按匹配内容的字符数替换成*public static String sensitiveFilter(String text, boolean isGreedMatch, SensitiveProcessor sensitiveProcessor)
text
- 文本isGreedMatch
- 贪婪匹配(最长匹配)原则:假如关键字a,ab,最长匹配将匹配[a, ab]sensitiveProcessor
- 敏感词处理器,默认按匹配内容的字符数替换成*Copyright © 2021. All rights reserved.