java 敏感字过滤
程序员文章站
2022-07-12 19:10:31
...
/**
*
* @param src 要过滤的语句
*/
@Override
public Set<String> checkSensitiveWords(String src) {
if(AppUtils.isBlank(src)){
return null;
}
// 把数据库中的敏感字 塑造成list集合
List<String> sensitiveWordList = sensitiveWordDao.getWords(sortId, nsortId, subNsortId);
Map<Character,List<String>> wordMap=new HashMap<Character,List<String>>();
for (String s:sensitiveWordList){
char c=s.charAt(0);
List<String> strs=wordMap.get(c);
if (strs==null){
strs=new ArrayList<String>();
wordMap.put(c,strs);
}
strs.add(s);
}
String temp=null;
String find;
char c;
Set<String> findwords = new HashSet<String>();
for (int i=0;i<src.length();i++){
c=src.charAt(i);
find=null;
if (wordMap.containsKey(c)){
List<String> words=wordMap.get(c);
for (String s:words){
temp=src.substring(i,(s.length()<=(src.length()-i))?i+s.length():i);
if (s.equals(temp)){
find=s;
break;
}
}
}
if (find!=null && findwords.size()<=10){
findwords.add(find);
i+=(find.length()-1);
}
}
return findwords;
}
请尊重知识,请尊重原创 更多资料参考请见 http://www.cezuwang.com/listFilm?page=1&areaId=906&filmTypeId=1