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