@Test public void getCommonRoots() { TrieNode node = new TrieNode(); TrieNode a = node.insert("/a"); TrieNode b = node.insert("/a/b"); TrieNode f = node.insert("/a/e/f"); TrieNode d = node.insert("/c/d"); TrieNode g = node.insert("/c/g"); Set<TrieNode> roots = Streams.stream(node.getCommonRoots()).collect(Collectors.toSet()); Assert.assertTrue(roots.contains(a)); Assert.assertFalse(roots.contains(b)); Assert.assertTrue(roots.contains(d)); Assert.assertFalse(roots.contains(f)); Assert.assertTrue(roots.contains(g)); }
public Iterator<TrieNode> getCommonRoots() { if (mIsTerminal) { return Collections.singletonList(this).iterator(); } return Iterators.concat(mChildren.values().stream().map(TrieNode::getCommonRoots).iterator()); }
TrieNode { public Iterator<TrieNode> getCommonRoots() { if (mIsTerminal) { return Collections.singletonList(this).iterator(); } return Iterators.concat(mChildren.values().stream().map(TrieNode::getCommonRoots).iterator()); } }
TrieNode { public Iterator<TrieNode> getCommonRoots() { if (mIsTerminal) { return Collections.singletonList(this).iterator(); } return Iterators.concat(mChildren.values().stream().map(TrieNode::getCommonRoots).iterator()); }  }
TrieNode { public Iterator<TrieNode> getCommonRoots() { if (mIsTerminal) { return Collections.singletonList(this).iterator(); } return Iterators.concat(mChildren.values().stream().map(TrieNode::getCommonRoots).iterator()); }  TrieNode insert(String path); List<TrieNode> search(String path); boolean hasTerminal(String path, boolean includeChildren); TrieNode deleteIf(String path, java.util.function.Function<TrieNode, Boolean> predicate); Iterator<TrieNode> getCommonRoots(); }
TrieNode { public Iterator<TrieNode> getCommonRoots() { if (mIsTerminal) { return Collections.singletonList(this).iterator(); } return Iterators.concat(mChildren.values().stream().map(TrieNode::getCommonRoots).iterator()); }  TrieNode insert(String path); List<TrieNode> search(String path); boolean hasTerminal(String path, boolean includeChildren); TrieNode deleteIf(String path, java.util.function.Function<TrieNode, Boolean> predicate); Iterator<TrieNode> getCommonRoots();  }