V
- the type of the value held by each nodepublic final class TrieNode<V> extends Object
Constructor and Description |
---|
TrieNode() |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Recursively removes all children.
|
TrieNode<V> |
deleteIf(String path,
java.util.function.Function<TrieNode<V>,Boolean> predicate)
Deletes the path from the Trie if the given predicate is true.
|
Iterator<TrieNode<V>> |
getCommonRoots() |
java.util.stream.Stream<TrieNode<V>> |
getLeafChildren(String path)
Get the terminal children of path (including path).
|
V |
getValue() |
boolean |
hasTerminal(String path,
boolean includeChildren)
Checks whether the path has terminal nodes as parents or children.
|
TrieNode<V> |
insert(String path)
Inserts a path into the trie.
|
List<TrieNode<V>> |
search(String path)
Traverses the trie along the path components until the traversal cannot proceed any more.
|
Optional<TrieNode<V>> |
searchExact(String path)
Find terminal component of the full path if one exists.
|
void |
setValue(V value)
Set the value associated with this node.
|
public void setValue(V value)
value
- the valuepublic V getValue()
public TrieNode<V> insert(String path)
path
- a path with components separated by "/"public List<TrieNode<V>> search(String path)
path
- the target pathpublic Optional<TrieNode<V>> searchExact(String path)
path
- the pathpublic boolean hasTerminal(String path, boolean includeChildren)
path
- the target pathincludeChildren
- whether the check should succeed if the path has children terminal nodespublic TrieNode<V> deleteIf(String path, java.util.function.Function<TrieNode<V>,Boolean> predicate)
path
- the target pathpredicate
- a predicate to decide whether the node should be deleted or notpublic Iterator<TrieNode<V>> getCommonRoots()
public java.util.stream.Stream<TrieNode<V>> getLeafChildren(String path)
path
- the pathpublic void clear()
Copyright © 2023. All Rights Reserved.