@Test public void testEnd() { String[] endPatternStrings = {"(B F $$$)", "(A B C $$$)"}; for (String endPatternString : endPatternStrings) { Tree<String> endPattern = TreeParserFactory.getStringTreeParser().parse(endPatternString); TreeGrep<String> matcher = new TreeGrep<>(endPattern); boolean result = matcher.matches(tree); assertEquals(true, result); } }
public boolean matches(Tree<T> tree) { boolean found = false; matchesList = new ArrayList<>(); for (Tree<T> node : TreeTraversal.breadthFirstTraversal(tree)) { if (verbose) { logger.info("Comparing node: "); logger.info(node.toString()); } nodeTreeMatches = new ArrayList<>(); nodeTreeMatches = doesNodeMatchPattern(node, getPattern(), nodeTreeMatches); if (nodeTreeMatches.size() > 0) { if (verbose) { logger.info("Found..."); } matchesList.addAll(nodeTreeMatches); found = true; } } return found; }
TreeGrep { public boolean matches(Tree<T> tree) { boolean found = false; matchesList = new ArrayList<>(); for (Tree<T> node : TreeTraversal.breadthFirstTraversal(tree)) { if (verbose) { logger.info("Comparing node: "); logger.info(node.toString()); } nodeTreeMatches = new ArrayList<>(); nodeTreeMatches = doesNodeMatchPattern(node, getPattern(), nodeTreeMatches); if (nodeTreeMatches.size() > 0) { if (verbose) { logger.info("Found..."); } matchesList.addAll(nodeTreeMatches); found = true; } } return found; } }
TreeGrep { public boolean matches(Tree<T> tree) { boolean found = false; matchesList = new ArrayList<>(); for (Tree<T> node : TreeTraversal.breadthFirstTraversal(tree)) { if (verbose) { logger.info("Comparing node: "); logger.info(node.toString()); } nodeTreeMatches = new ArrayList<>(); nodeTreeMatches = doesNodeMatchPattern(node, getPattern(), nodeTreeMatches); if (nodeTreeMatches.size() > 0) { if (verbose) { logger.info("Found..."); } matchesList.addAll(nodeTreeMatches); found = true; } } return found; } TreeGrep(Tree<T> pattern); }
TreeGrep { public boolean matches(Tree<T> tree) { boolean found = false; matchesList = new ArrayList<>(); for (Tree<T> node : TreeTraversal.breadthFirstTraversal(tree)) { if (verbose) { logger.info("Comparing node: "); logger.info(node.toString()); } nodeTreeMatches = new ArrayList<>(); nodeTreeMatches = doesNodeMatchPattern(node, getPattern(), nodeTreeMatches); if (nodeTreeMatches.size() > 0) { if (verbose) { logger.info("Found..."); } matchesList.addAll(nodeTreeMatches); found = true; } } return found; } TreeGrep(Tree<T> pattern); boolean matches(Tree<T> tree); boolean doesThisTreeMatch(Tree<T> tree); List<TreeGrepMatch<T>> getMatches(); @Override String toString(); Tree<T> getPattern(); }
TreeGrep { public boolean matches(Tree<T> tree) { boolean found = false; matchesList = new ArrayList<>(); for (Tree<T> node : TreeTraversal.breadthFirstTraversal(tree)) { if (verbose) { logger.info("Comparing node: "); logger.info(node.toString()); } nodeTreeMatches = new ArrayList<>(); nodeTreeMatches = doesNodeMatchPattern(node, getPattern(), nodeTreeMatches); if (nodeTreeMatches.size() > 0) { if (verbose) { logger.info("Found..."); } matchesList.addAll(nodeTreeMatches); found = true; } } return found; } TreeGrep(Tree<T> pattern); boolean matches(Tree<T> tree); boolean doesThisTreeMatch(Tree<T> tree); List<TreeGrepMatch<T>> getMatches(); @Override String toString(); Tree<T> getPattern(); static String endOfChildrenString; static String startOfChildrenString; }