This commit is contained in:
Looly 2022-03-16 22:55:39 +08:00
parent 5fdabe844e
commit c693b28cbf

View File

@ -1,7 +1,6 @@
package cn.hutool.dfa; package cn.hutool.dfa;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Filter; import cn.hutool.core.lang.Filter;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@ -86,8 +85,7 @@ public class WordTree extends HashMap<Character, WordTree> {
* @return this * @return this
*/ */
public WordTree addWords(String... words) { public WordTree addWords(String... words) {
HashSet<String> wordsSet = CollectionUtil.newHashSet(words); for (String word : CollUtil.newHashSet(words)) {
for (String word : wordsSet) {
addWord(word); addWord(word);
} }
return this; return this;
@ -105,7 +103,7 @@ public class WordTree extends HashMap<Character, WordTree> {
WordTree current = this; WordTree current = this;
WordTree child; WordTree child;
char currentChar = 0; char currentChar = 0;
int length = word.length(); final int length = word.length();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
currentChar = word.charAt(i); currentChar = word.charAt(i);
if (charFilter.accept(currentChar)) {//只处理合法字符 if (charFilter.accept(currentChar)) {//只处理合法字符