[feature] 添加递归扁平化WordTree方法,能通过WordTree还原成原来的元素

This commit is contained in:
VampireAchao
2024-01-14 13:07:43 +08:00
committed by VampireAchao
parent 4ccf795ee0
commit bf0977445a
2 changed files with 50 additions and 0 deletions

View File

@@ -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);
}
}