TreeMatcher { public Stream<TreeMatchResult<V>> results() { return _tree.stream() .flatMap(tree -> _pattern.match(tree).stream()); } private  TreeMatcher(final TreePattern<V> pattern, final Tree<V, ?> tree); TreePattern<V> pattern(); Tree<V, ?> tree(); boolean matches(); Stream<TreeMatchResult<V>> results();  }
@Test(dataProvider = "matchResults") public void results( final String patternString, final String treeString, final String[] results ) { final TreePattern<String> pattern = TreePattern.compile(patternString); final Tree<String, ?> tree = TreeNode.parse(treeString); final String[] matches = pattern.matcher(tree).results() .map(t -> t.tree().toParenthesesString()) .toArray(String[]::new); Assert.assertEquals(matches, results); }