This commit is contained in:
Looly 2019-10-10 17:18:31 +08:00
parent 96cf2503cc
commit 314cb1b64c
3 changed files with 15 additions and 6 deletions

View File

@ -9,4 +9,4 @@
* 【all】 升级JDK最低支持到8 * 【all】 升级JDK最低支持到8
### Bug修复 ### Bug修复
* 【http】 修复Cookie中host失效导致的问题 * 【http】 修复Cookie中host失效导致的问题issue#583@Github

View File

@ -160,7 +160,7 @@ public class WordTree extends HashMap<Character, WordTree>{
return null; return null;
} }
List<String> findedWords = new ArrayList<String>(); List<String> foundWords = new ArrayList<>();
WordTree current = this; WordTree current = this;
int length = text.length(); int length = text.length();
//存放查找到的字符缓存完整出现一个词时加到findedWords中否则清空 //存放查找到的字符缓存完整出现一个词时加到findedWords中否则清空
@ -187,10 +187,10 @@ public class WordTree extends HashMap<Character, WordTree>{
wordBuffer.append(currentChar); wordBuffer.append(currentChar);
if(current.isEnd(currentChar)){ if(current.isEnd(currentChar)){
//到达单词末尾关键词成立从此词的下一个位置开始查找 //到达单词末尾关键词成立从此词的下一个位置开始查找
findedWords.add(wordBuffer.toString()); foundWords.add(wordBuffer.toString());
if(limit > 0 && findedWords.size() >= limit){ if(limit > 0 && foundWords.size() >= limit){
//超过匹配限制个数直接返回 //超过匹配限制个数直接返回
return findedWords; return foundWords;
} }
if(false == isDensityMatch){ if(false == isDensityMatch){
//如果非密度匹配跳过匹配到的词 //如果非密度匹配跳过匹配到的词
@ -208,7 +208,7 @@ public class WordTree extends HashMap<Character, WordTree>{
} }
current = this; current = this;
} }
return findedWords; return foundWords;
} }

View File

@ -93,6 +93,15 @@ public class DfaTest {
List<String> all = tree.matchAll("AAAAAAAt-ioBBBBBBB"); List<String> all = tree.matchAll("AAAAAAAt-ioBBBBBBB");
Assert.assertEquals(all, CollectionUtil.newArrayList("t-io")); Assert.assertEquals(all, CollectionUtil.newArrayList("t-io"));
} }
@Test
public void aTest(){
WordTree tree = new WordTree();
tree.addWord("women");
String text = "a WOMEN todo.".toLowerCase();
List<String> matchAll = tree.matchAll(text, -1, false, false);
Assert.assertEquals("[women]", matchAll.toString());
}
// ---------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------
/** /**