@Test public void hasTerminal() { TrieNode node = new TrieNode(); node.insert("/a/b"); Assert.assertFalse(node.hasTerminal("/", false)); Assert.assertFalse(node.hasTerminal("/c", false)); Assert.assertFalse(node.hasTerminal("/a", false)); Assert.assertTrue(node.hasTerminal("/a/b", false)); Assert.assertTrue(node.hasTerminal("/a/b/c", false)); }
public boolean hasTerminal(String path, boolean includeChildren) { TrieNode current = this; if (current.mIsTerminal) { return true; } for (String component : path.split("/")) { TrieNode child = current.mChildren.get(component); if (child != null) { current = child; if (current.mIsTerminal) { return true; } } else { return false; } } return includeChildren; }
TrieNode { public boolean hasTerminal(String path, boolean includeChildren) { TrieNode current = this; if (current.mIsTerminal) { return true; } for (String component : path.split("/")) { TrieNode child = current.mChildren.get(component); if (child != null) { current = child; if (current.mIsTerminal) { return true; } } else { return false; } } return includeChildren; } }
TrieNode { public boolean hasTerminal(String path, boolean includeChildren) { TrieNode current = this; if (current.mIsTerminal) { return true; } for (String component : path.split("/")) { TrieNode child = current.mChildren.get(component); if (child != null) { current = child; if (current.mIsTerminal) { return true; } } else { return false; } } return includeChildren; }  }
TrieNode { public boolean hasTerminal(String path, boolean includeChildren) { TrieNode current = this; if (current.mIsTerminal) { return true; } for (String component : path.split("/")) { TrieNode child = current.mChildren.get(component); if (child != null) { current = child; if (current.mIsTerminal) { return true; } } else { return false; } } return includeChildren; }  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 boolean hasTerminal(String path, boolean includeChildren) { TrieNode current = this; if (current.mIsTerminal) { return true; } for (String component : path.split("/")) { TrieNode child = current.mChildren.get(component); if (child != null) { current = child; if (current.mIsTerminal) { return true; } } else { return false; } } return includeChildren; }  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();  }