001    package org.hackystat.telemetry.analyzer.configuration;
002    
003    import java.io.FileFilter;
004    import java.io.File;
005    
006    /**
007     * Provides a file filter that accepts only files with a given case-insensitive extension.
008     *
009     * @author    Philip M. Johnson
010     * @version   $Id: ExtensionFileFilter.java,v 1.1.1.1 2005/10/20 23:56:44 johnson Exp $
011     */
012    public class ExtensionFileFilter implements FileFilter {
013      /** The wanted extension. */
014      private String extension;
015    
016      /**
017       * Creates a file filter that accepts only files with the given extension, case-insensitive.
018       *
019       * @param extension  The extension string (typically including the ".").
020       */
021      public ExtensionFileFilter(String extension) {
022        this.extension = extension.toLowerCase();
023      }
024    
025      /**
026       * Determines if the passed file should be filtered or not.
027       *
028       * @param file  The file to be (potentially) filtered.
029       * @return      True if the file has the specified extension, false otherwise.
030       */
031      public boolean accept(File file) {
032        if (file.isDirectory()) {
033          return false;
034        }
035        return file.getName().toLowerCase().endsWith(this.extension);
036      }
037    }
038    
039