use of org.trie4j.patricia.PatriciaTrie in project trie4j by takawitter.
the class TailLOUDSPPTrieWithConcatTailArrayTest method test_save_load.
@Test
public void test_save_load() throws Exception {
String[] words = { "こんにちは", "さようなら", "おはよう", "おおきなかぶ", "おおやまざき" };
Trie trie = new PatriciaTrie(words);
TailLOUDSTrie lt = new TailLOUDSTrie(trie, new LOUDSPPBvTree(trie.nodeSize()));
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
lt.writeExternal(oos);
oos.flush();
lt = new TailLOUDSTrie(new PatriciaTrie(), new LOUDSPPBvTree());
lt.readExternal(new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())));
for (String w : words) {
Assert.assertTrue(lt.contains(w));
}
Assert.assertFalse(lt.contains("おやすみなさい"));
}
StringBuilder b = new StringBuilder();
Node[] children = lt.getRoot().getChildren();
for (Node n : children) {
char[] letters = n.getLetters();
b.append(letters[0]);
}
Assert.assertEquals("おこさ", b.toString());
}
Aggregations