public final class TreeMatcher<V> extends Object
final TreePattern<String> pattern = TreePattern.compile("add($x,$y)");
final Tree<String, ?> tree = TreeNode.parse("add(1,add(2,3))");
final TreeMatcher<String> matcher = pattern.matcher(tree);
matcher.results().forEach(r -> System.out.println(r.tree().toParenthesesString()));
// Prints:
// add(1,add(2,3))
// add(2,3)
TreePattern.matcher(Tree)
Modifier and Type | Method and Description |
---|---|
boolean |
matches()
Tests if the tree matches the pattern.
|
TreePattern<V> |
pattern()
Return the underlying pattern of
this matcher. |
Stream<TreeMatchResult<V>> |
results()
Return all matching sub-trees.
|
Tree<V,?> |
tree()
Return the matching tree.
|
public TreePattern<V> pattern()
this
matcher.public boolean matches()
true
if the tree matches against the pattern,
false
otherwiseNullPointerException
- if the given predicate is null
public Stream<TreeMatchResult<V>> results()
NullPointerException
- if the given predicate is null
© 2007-2019 Franz Wilhelmstötter (2019-11-18 20:30)