View Javadoc

    1   /**
    2    *
    3    */
    4   package net.sourceforge.pmd.cpd;
    5
    6   import net.sourceforge.pmd.SourceFileSelector;
    7
    8   import java.io.File;
    9   import java.io.FilenameFilter;
    10
    11  /**
    12   * Filtering of directories en wanted source files.
    13   */
    14  public class SourceFileOrDirectoryFilter implements FilenameFilter {
    15
    16      private SourceFileSelector fileSelector;
    17
    18      private static final String fileSeparator = System.getProperty("file.separator");
    19
    20      /**
    21       * Public constructor
    22       *
    23       * @param fileSelector the FileSelector that knows what source files to accept
    24       */
    25      public SourceFileOrDirectoryFilter(SourceFileSelector fileSelector) {
    26          this.fileSelector = fileSelector;
    27      }
    28
    29      public boolean accept(File dir, String filename) {
    30          return (fileSelector.isWantedFile(filename) || (new File(dir.getAbsolutePath() + fileSeparator + filename).isDirectory())) && !filename.equals("SCCS");
    31  // Remark: Why not use "new File(dir, filename).isDirectory()" ?
    32      }
    33  }