Example #1
0
  private void process(File dir, String fileName, List<Pattern> matchingIncludes) {
    // Increment patterns that need to move to the next token.
    boolean isFinalMatch = false;
    List<Pattern> incrementedPatterns = new ArrayList();
    for (Iterator iter = matchingIncludes.iterator(); iter.hasNext(); ) {
      Pattern include = (Pattern) iter.next();
      if (include.incr(fileName)) {
        incrementedPatterns.add(include);
        if (include.isExhausted()) iter.remove();
      }
      if (include.wasFinalMatch()) isFinalMatch = true;
    }

    File file = new File(dir, fileName);
    if (isFinalMatch) {
      int length = rootDir.getPath().length();
      if (!rootDir.getPath().endsWith(File.separator)) length++; // Lose starting slash.
      matches.add(file.getPath().substring(length));
    }
    if (!matchingIncludes.isEmpty() && file.isDirectory()) scanDir(file, matchingIncludes);

    // Decrement patterns.
    for (Pattern include : incrementedPatterns) include.decr();
  }