protected List<Node> findMatch(Node start, List<Pattern> patterns) { // Get the next pattern in sequence final Pattern pattern = patterns.get(0); if (!pattern.matches(start)) { return Collections.emptyList(); } // Hold the matched Nodes final List<Node> matchedNodes = new ArrayList<Node>(); if (patterns.size() == 1) { matchedNodes.add(start); return matchedNodes; } for (final Node child : start.getChildren()) { // Only use patterns that haven't already matched final List<Pattern> remainingPatterns = patterns.subList(1, patterns.size()); // Recursion point matchedNodes.addAll(findMatch(child, remainingPatterns)); } return matchedNodes; }
protected List<Node> findMatch(Node start, List<Pattern> patterns) { // Get the next pattern in sequence final Pattern pattern = patterns.get(0); if (!pattern.matches(start)) { return Collections.emptyList(); } // Hold the matched Nodes final List<Node> matchedNodes = new ArrayList<Node>(); if (patterns.size() == 1) { matchedNodes.add(start); return matchedNodes; } for (final Node child : start.getChildren()) { // Only use patterns that haven't already matched final List<Pattern> remainingPatterns = patterns.subList(1, patterns.size()); // Recursion point matchedNodes.addAll(findMatch(child, remainingPatterns)); } return matchedNodes; }
private List<Node> findMatch(final Node start, final List<Pattern> patternSequence, final List<Pattern> entirePatternSequence) { // Hold the matched Nodes final List<Node> matchedNodes = new ArrayList<Node>(); // Get the next pattern in sequence final Pattern pattern = patternSequence.get(0); // See if we've got a match if (pattern.matches(start)) { // If no more patterns to check, we're at the end of the line; just add this Node if (patternSequence.size() == 1) { matchedNodes.add(start); } else { for (final Node child : start.getChildren()) { // Only use patterns that haven't already matched final List<Pattern> remainingPatterns = patternSequence.subList(1, patternSequence.size()); // Recursion point matchedNodes.addAll(findMatch(child, remainingPatterns, entirePatternSequence)); } } } // Apply whole pattern sequence starting from the subtrees // created by node's children for (final Node child : start.getChildren()) { matchedNodes.addAll(findMatch(child, entirePatternSequence, entirePatternSequence)); } return matchedNodes; }
private List<Node> findMatch(final Node start, final List<Pattern> patternSequence, final List<Pattern> entirePatternSequence) { // Hold the matched Nodes final List<Node> matchedNodes = new ArrayList<Node>(); // Get the next pattern in sequence final Pattern pattern = patternSequence.get(0); // See if we've got a match if (pattern.matches(start)) { // If no more patterns to check, we're at the end of the line; just add this Node if (patternSequence.size() == 1) { matchedNodes.add(start); } else { for (final Node child : start.getChildren()) { // Only use patterns that haven't already matched final List<Pattern> remainingPatterns = patternSequence.subList(1, patternSequence.size()); // Recursion point matchedNodes.addAll(findMatch(child, remainingPatterns, entirePatternSequence)); } } } // Apply whole pattern sequence starting from the subtrees // created by node's children for (final Node child : start.getChildren()) { matchedNodes.addAll(findMatch(child, entirePatternSequence, entirePatternSequence)); } return matchedNodes; }