java.lang.Object
io.jenetics.ext.rewriting.TreeMatcher<V>
Implementation of a pattern-based tree matcher. It allows you to iterate over
all matches of a tree for a given pattern.
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)
- Since:
- 5.0
- Version:
- 5.0
- See Also:
-
Method Summary
-
Method Details
-
pattern
Return the underlying pattern ofthis
matcher.- Returns:
- the underlying tree pattern
-
tree
Return the matching tree.- Returns:
- the matching tree
-
matches
Tests if the tree matches the pattern.- Returns:
true
if the tree matches against the pattern,false
otherwise- Throws:
NullPointerException
- if the given predicate isnull
-
results
Return all matching sub-trees.- Returns:
- all matching subtrees
- Throws:
NullPointerException
- if the given predicate isnull
-