Package io.jenetics.ext.rewriting
Class TreeMatcher<V>
- java.lang.Object
-
- io.jenetics.ext.rewriting.TreeMatcher<V>
-
public final class TreeMatcher<V> extends Object
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:
TreePattern.matcher(Tree)
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
matches()
Tests if the tree matches the pattern.TreePattern<V>
pattern()
Return the underlying pattern ofthis
matcher.Stream<TreeMatchResult<V>>
results()
Return all matching sub-trees.Tree<V,?>
tree()
Return the matching tree.
-
-
-
Method Detail
-
pattern
public TreePattern<V> pattern()
Return the underlying pattern ofthis
matcher.- Returns:
- the underlying tree pattern
-
matches
public boolean 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
public Stream<TreeMatchResult<V>> results()
Return all matching sub-trees.- Returns:
- all matching sub-trees
- Throws:
NullPointerException
- if the given predicate isnull
-
-