mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
[feature] 添加递归扁平化WordTree方法,能通过WordTree还原成原来的元素
This commit is contained in:
committed by
VampireAchao
parent
4ccf795ee0
commit
bf0977445a
@@ -16,6 +16,8 @@ import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -209,4 +211,14 @@ public class DfaTest {
|
||||
strings = wordTree.matchAll("abab", -1, true, true);
|
||||
Assertions.assertEquals("[ab, b, ab, b]", strings.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void flattenTest() {
|
||||
final WordTree wordTree = new WordTree();
|
||||
final List<String> list = Arrays.asList("阿帕奇", "阿超", "HuTool", "HuTao");
|
||||
wordTree.addWords(list);
|
||||
final List<String> flattened = wordTree.flatten();
|
||||
flattened.sort(Comparator.comparingInt(list::indexOf));
|
||||
Assertions.assertEquals(list, flattened);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user