You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by je...@apache.org on 2003/11/22 21:03:52 UTC

cvs commit: jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter FileFilterUtils.java

jeremias    2003/11/22 12:03:52

  Modified:    io/src/java/org/apache/commons/io/filefilter
                        FileFilterUtils.java
  Log:
  Add the new name filter.
  Add method to decorate a filter to become "CVS-aware", thus filtering out all CVS directories. This is driven by some functionality in FileUtils as I'm refactoring that class.
  
  Revision  Changes    Path
  1.6       +40 -2     jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java
  
  Index: FileFilterUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FileFilterUtils.java	13 Oct 2003 07:03:50 -0000	1.5
  +++ FileFilterUtils.java	22 Nov 2003 20:03:52 -0000	1.6
  @@ -57,13 +57,16 @@
   import java.io.FilenameFilter;
   
   /**
  - * Useful utilities for working with file filters.
  + * Useful utilities for working with file filters. It provides access to all
  + * file filter implementations in this package so you don't have to import
  + * every classes you use.
    * 
    * @since Commons IO 1.0
    * @version $Revision$ $Date$
    * 
    * @author Henri Yandell
    * @author Stephen Colebourne
  + * @author Jeremias Maerki
    */
   public class FileFilterUtils {
       
  @@ -95,6 +98,16 @@
       }
   
       /**
  +     * Returns a filter that returns true if the filename matches the specified text.
  +     * 
  +     * @param name  the filename
  +     * @return a name checking filter
  +     */
  +    public static IOFileFilter nameFileFilter(String name) {
  +        return new NameFileFilter(name);
  +    }
  +
  +    /**
        * Returns a filter that checks if the file is a directory.
        * 
        * @return directory file filter
  @@ -176,6 +189,31 @@
        */
       public static IOFileFilter asFileFilter(FilenameFilter filter) {
           return new DelegateFileFilter(filter);
  +    }
  +
  +    //-----------------------------------------------------------------------
  +
  +    /* Constructed on demand and then cached */
  +    private static IOFileFilter cvsFilter = null;
  +
  +    /**
  +     * Resturns an IOFileFilter that ignores CVS directories. You may optionally
  +     * pass in an existing IOFileFilter in which case it is extended to exclude
  +     * CVS directories.
  +     * @param filter IOFileFilter to modify, null if a new IOFileFilter
  +     * should be created
  +     * @return the requested (combined) filter
  +     */
  +    public static IOFileFilter makeCVSAware(IOFileFilter filter) {
  +        if (cvsFilter == null) {
  +            cvsFilter = andFileFilter(directoryFileFilter(), 
  +                notFileFilter(nameFileFilter("CVS")));
  +        }
  +        if (filter == null) {
  +            return cvsFilter;
  +        } else {
  +            return andFileFilter(filter, cvsFilter);
  +        }
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org