You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/05/17 00:33:48 UTC

cvs commit: jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter TrueFileFilter.java SuffixFileFilter.java FalseFileFilter.java AndFileFilter.java NotFileFilter.java OrFileFilter.java IOFileFilter.java AbstractFileFilter.java FileFilterUtils.java DirectoryFileFilter.java PrefixFileFilter.java DelegateFileFilter.java ExtensionFileFilter.java PredicateFileFilter.java FileFilter.java

scolebourne    2003/05/16 15:33:47

  Modified:    io/src/java/org/apache/commons/io/filefilter
                        AbstractFileFilter.java FileFilterUtils.java
                        DirectoryFileFilter.java PrefixFileFilter.java
                        DelegateFileFilter.java
  Added:       io/src/java/org/apache/commons/io/filefilter
                        TrueFileFilter.java SuffixFileFilter.java
                        FalseFileFilter.java AndFileFilter.java
                        NotFileFilter.java OrFileFilter.java
                        IOFileFilter.java
  Removed:     io/src/java/org/apache/commons/io/filefilter
                        ExtensionFileFilter.java PredicateFileFilter.java
                        FileFilter.java
  Log:
  Refactor filefilter directory to remove dependency on lang
  
  Revision  Changes    Path
  1.5       +32 -25    jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/AbstractFileFilter.java
  
  Index: AbstractFileFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/AbstractFileFilter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractFileFilter.java	7 Dec 2002 20:29:24 -0000	1.4
  +++ AbstractFileFilter.java	16 May 2003 22:33:46 -0000	1.5
  @@ -1,9 +1,7 @@
  -package org.apache.commons.io.filefilter;
  -
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -54,36 +52,45 @@
    * <http://www.apache.org/>.
    *
    */
  +package org.apache.commons.io.filefilter;
   
  -import java.io.FilenameFilter;
   import java.io.File;
   
  -import org.apache.commons.lang.functor.Predicate;
  -
   /**
  - * An abstract class which brings the FileFilter and FilenameFilter 
  - * interfaces together, through the IO.FileFilter interface. Note that 
  - * you <b>must</b> override one of the methods ellse your class will 
  - * infinitely loop.
  - *
  + * An abstract class which implements the Java FileFilter and FilenameFilter 
  + * interfaces via the IOFileFilter interface.
  + * <p>
  + * Note that a subclass <b>must</b> override one of the accept methods,
  + * otherwise your class will infinitely loop.
  + *
  + * @since Commons IO 1.0
  + * @version $Revision$ $Date$
  + * 
  + * @author Henri Yandell
  + * @author Stephen Colebourne
    */
  -public abstract class AbstractFileFilter
  -implements FileFilter
  -{
  -
  -    /** Defined in Predicate */
  -    public boolean evaluate(Object object) {
  -        return accept( (File)object );
  -    }
  +public abstract class AbstractFileFilter implements IOFileFilter {
   
  -    /** Defined in FileFilter */
  -    public boolean accept( File f) {
  -        return accept( f.getParentFile(), f.getName());
  +    /**
  +     * Checks to see if the File should be accepted by this filter.
  +     * 
  +     * @param file  the File to check
  +     * @return true if this file matches the test
  +     */
  +    public boolean accept(final File file) {
  +        return accept(file.getParentFile(), file.getName());
       }
   
  -    /** Defined in FilenameFilter */
  -    public boolean accept( File dir, String name) {
  -        return accept( new File( dir.getName() + File.separator + name ) );
  +    /**
  +     * Checks to see if the File should be accepted by this filter.
  +     * 
  +     * @param file  the directory File to check
  +     * @param name  the filename within the directory to check
  +     * @return true if this file matches the test
  +     */
  +    public boolean accept(final File dir, final String name) {
  +        String filename = dir.getName() + File.separator + name;
  +        return accept(new File(filename));
       }
   
   }
  
  
  
  1.2       +146 -27   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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileFilterUtils.java	7 Dec 2002 20:29:24 -0000	1.1
  +++ FileFilterUtils.java	16 May 2003 22:33:46 -0000	1.2
  @@ -1,35 +1,154 @@
  +/* ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + *    if any, must include the following acknowledgment:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + *    "Apache Turbine" must not be used to endorse or promote products
  + *    derived from this software without prior written permission. For
  + *    written permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + *    "Apache Turbine", nor may "Apache" appear in their name, without
  + *    prior written permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + *
  + */
   package org.apache.commons.io.filefilter;
   
  -import org.apache.commons.lang.functor.Predicate;
  -import org.apache.commons.lang.functor.PredicateUtils;
  -
  +/**
  + * Useful utilities for working with file filters.
  + * 
  + * @since Commons IO 1.0
  + * @version $Revision$ $Date$
  + * 
  + * @author Henri Yandell
  + * @author Stephen Colebourne
  + */
   public class FileFilterUtils {
  -
  +    
  +    /**
  +     * FileFilterUtils is not normally instantiated.
  +     */
       public FileFilterUtils() {
       }
   
  -    static public FileFilter predicateToFileFilter(Predicate predicate) {
  -        return new PredicateFileFilter(predicate);
  -    }
  -
  -    static public FileFilter andFileFilter(FileFilter f1, FileFilter f2) {
  -        return predicateToFileFilter(
  -            PredicateUtils.andPredicate( f1, f2 ) 
  -            );
  -    }
  -
  -    static public FileFilter orFileFilter(FileFilter f1, FileFilter f2) {
  -        return predicateToFileFilter(
  -            PredicateUtils.orPredicate( f1, f2 ) 
  -            );
  +    //-----------------------------------------------------------------------
  +    /**
  +     * Returns a filter that returns true if the filename starts with the specified text.
  +     * 
  +     * @param prefix  the filename prefix
  +     * @return a prefix checking filter
  +     */
  +    public static IOFileFilter prefixFileFilter(String prefix) {
  +        return new PrefixFileFilter(prefix);
  +    }
  +
  +    /**
  +     * Returns a filter that returns true if the filename ends with the specified text.
  +     * 
  +     * @param suffix  the filename suffix
  +     * @return a suffix checking filter
  +     */
  +    public static IOFileFilter suffixFileFilter(String suffix) {
  +        return new SuffixFileFilter(suffix);
  +    }
  +
  +    /**
  +     * Returns a filter that checks if the file is a directory.
  +     * 
  +     * @return directory file filter
  +     */
  +    public static IOFileFilter directoryFileFilter() {
  +        return DirectoryFileFilter.INSTANCE;
  +    }
  +    
  +    /**
  +     * Returns a filter that ANDs the two specified filters.
  +     * 
  +     * @param filter1  the first filter
  +     * @param filter2  the second filter
  +     * @return a filter that ANDs the two specified filters
  +     */
  +    public static IOFileFilter andFileFilter(IOFileFilter filter1, IOFileFilter filter2) {
  +        return new AndFileFilter(filter1, filter2);
  +    }
  +
  +    /**
  +     * Returns a filter that ORs the two specified filters.
  +     * 
  +     * @param filter1  the first filter
  +     * @param filter2  the second filter
  +     * @return a filter that ORs the two specified filters
  +     */
  +    public static IOFileFilter orFileFilter(IOFileFilter filter1, IOFileFilter filter2) {
  +        return new OrFileFilter(filter1, filter2);
  +    }
  +
  +    /**
  +     * Returns a filter that NOTs the specified filter.
  +     * 
  +     * @param filter  the filter to invert
  +     * @return a filter that NOTs the specified filter
  +     */
  +    public static IOFileFilter notFileFilter(IOFileFilter filter) {
  +        return new NotFileFilter(filter);
  +    }
  +
  +    /**
  +     * Returns a filter that always returns true.
  +     * 
  +     * @return a true filter
  +     */
  +    public static IOFileFilter trueFileFilter() {
  +        return TrueFileFilter.INSTANCE;
  +    }
  +
  +    /**
  +     * Returns a filter that always returns false.
  +     * 
  +     * @return a false filter
  +     */
  +    public static IOFileFilter falseFileFilter() {
  +        return FalseFileFilter.INSTANCE;
       }
  -
  -    static public FileFilter nullFileFilter() {
  -        return predicateToFileFilter( PredicateUtils.nullPredicate() );
  -    }
  -
  -    static public FileFilter notFileFilter(FileFilter f) {
  -        return predicateToFileFilter( PredicateUtils.notPredicate( f ) );
  -    }
  -
  +    
   }
  
  
  
  1.2       +33 -17    jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java
  
  Index: DirectoryFileFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DirectoryFileFilter.java	28 Jul 2002 03:10:01 -0000	1.1
  +++ DirectoryFileFilter.java	16 May 2003 22:33:46 -0000	1.2
  @@ -1,9 +1,7 @@
  -package org.apache.commons.io.filefilter;
  -
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -53,32 +51,50 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  +package org.apache.commons.io.filefilter;
  +
   import java.io.File;
   
   /**
    * This filter accepts <code>File</code>s that are directories.
  - * <p>Eg., here is how to print out a list of the current directory's subdirectories:</p>
  + * <p>
  + * For example, here is how to print out a list of the 
  + * current directory's subdirectories:
    *
    * <pre>
    * File dir = new File(".");
  - * String[] files = dir.list( new DirectoryFileFilter() );
  - * for ( int i=0; i&lt;files.length; i++ )
  - * {
  + * String[] files = dir.list( DirectoryFileFilter.INSTANCE );
  + * for ( int i = 0; i &lt; files.length; i++ ) {
    *     System.out.println(files[i]);
    * }
    * </pre>
    *
  - * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  + * @since Commons IO 1.0
    * @version $Revision$ $Date$
  - * @since 4.0
  + * 
  + * @author Henri Yandell
  + * @author Stephen Colebourne
  + * @author Peter Donald
    */
  -public class DirectoryFileFilter
  -    extends AbstractFileFilter
  -{
  -    public boolean accept( final File file )
  -    {
  +public class DirectoryFileFilter extends AbstractFileFilter {
  +    
  +    /** Singleton instance of directory filter */
  +    public static final IOFileFilter INSTANCE = new DirectoryFileFilter();
  +    
  +    /**
  +     * Restrictive consructor.
  +     */
  +    protected DirectoryFileFilter() {
  +    }
  +    
  +    /**
  +     * Checks to see if the file is a directory.
  +     * 
  +     * @param file  the File to check
  +     * @return true if the file is a directory
  +     */
  +    public boolean accept(final File file) {
           return file.isDirectory();
       }
  +    
   }
  -
  -
  
  
  
  1.2       +82 -32    jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java
  
  Index: PrefixFileFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PrefixFileFilter.java	28 Jul 2002 03:10:01 -0000	1.1
  +++ PrefixFileFilter.java	16 May 2003 22:33:47 -0000	1.2
  @@ -1,9 +1,7 @@
  -package org.apache.commons.io.filefilter;
  -
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -53,56 +51,108 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  +package org.apache.commons.io.filefilter;
   
   import java.io.File;
  -import java.io.FilenameFilter;
  +import java.util.List;
   
   /**
    * This filters filenames for a certain prefix.
  - *
  - * <p>Eg., to print all files and directories in the current directory whose name starts with</p>
  - * <code>foo</code>:
  + * <p>
  + * For example, to print all files and directories in the 
  + * current directory whose name starts with <code>foo</code>:
    *
    * <pre>
    * File dir = new File(".");
    * String[] files = dir.list( new PrefixFileFilter("foo"));
  - * for ( int i=0; i&lt;files.length; i++ )
  - * {
  + * for ( int i = 0; i &lt; files.length; i++ ) {
    *     System.out.println(files[i]);
    * }
    * </pre>
    *
  - *
  - * @author  Federico Barbieri <fe...@apache.org>
  - * @author Serge Knystautas <se...@lokitech.com>
  - * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version CVS $Revision$ $Date$
  - * @since 4.0
  + * @since Commons IO 1.0
  + * @version $Revision$ $Date$
  + * 
  + * @author Henri Yandell
  + * @author Stephen Colebourne
  + * @author Federico Barbieri
  + * @author Serge Knystautas
  + * @author Peter Donald
    */
  -public class PrefixFileFilter
  -    extends AbstractFileFilter
  -{
  -    private String[] m_prefixs;
  -
  -    public PrefixFileFilter( final String[] prefixs )
  -    {
  -        m_prefixs = prefixs;
  +public class PrefixFileFilter extends AbstractFileFilter {
  +    
  +    /** The filename prefix to search for */
  +    private String[] prefixes;
  +
  +    /**
  +     * Constructs a new Prefix file filter for a single prefix.
  +     * 
  +     * @param prefix  the prefix to allow, null means none
  +     */
  +    public PrefixFileFilter(final String prefix) {
  +        if (prefixes == null) {
  +            throw new IllegalArgumentException("The prefix must not be null");
  +        }
  +        this.prefixes = new String[] {prefix};
       }
   
  -    public PrefixFileFilter( final String prefix )
  -    {
  -        m_prefixs = new String[]{prefix};
  +    /**
  +     * Constructs a new Prefix file filter for an array of prefixes.
  +     * <p>
  +     * The array is not cloned, so could be changed after constructing the
  +     * instance. This would be inadvisable however.
  +     * 
  +     * @param prefixes  the prefixes to allow, null means none
  +     */
  +    public PrefixFileFilter(final String[] prefixes) {
  +        if (prefixes == null) {
  +            throw new IllegalArgumentException("The array of prefixes must not be null");
  +        }
  +        this.prefixes = prefixes;
       }
   
  -    public boolean accept( final File file, final String name )
  -    {
  -        for( int i = 0; i < m_prefixs.length; i++ )
  -        {
  -            if( name.startsWith( m_prefixs[ i ] ) )
  -            {
  +    /**
  +     * Constructs a new Prefix file filter for a list of prefixes.
  +     * 
  +     * @param prefixes  the prefixes to allow, null means none
  +     */
  +    public PrefixFileFilter(final List prefixes) {
  +        if (prefixes == null) {
  +            throw new IllegalArgumentException("The list of prefixes must not be null");
  +        }
  +        this.prefixes = (String[]) prefixes.toArray(new String[prefixes.size()]);
  +    }
  +
  +    /**
  +     * Checks to see if the filename ends with the prefix.
  +     * 
  +     * @param file  the File to check
  +     * @return true if the filename starts with one of our prefixes
  +     */
  +    public boolean accept(final File file) {
  +        String name = file.getName();
  +        for (int i = 0; i < this.prefixes.length; i++) {
  +            if (name.startsWith(this.prefixes[i])) {
  +                return true;
  +            }
  +        }
  +        return false;
  +    }
  +    
  +    /**
  +     * Checks to see if the filename starts with the prefix.
  +     * 
  +     * @param file  the File directory
  +     * @param name  the filename
  +     * @return true if the filename starts with one of our prefixes
  +     */
  +    public boolean accept(final File file, final String name) {
  +        for (int i = 0; i < prefixes.length; i++) {
  +            if (name.startsWith(prefixes[i])) {
                   return true;
               }
           }
           return false;
       }
  +    
   }
  
  
  
  1.5       +55 -30    jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/DelegateFileFilter.java
  
  Index: DelegateFileFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/DelegateFileFilter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DelegateFileFilter.java	7 Dec 2002 20:29:24 -0000	1.4
  +++ DelegateFileFilter.java	16 May 2003 22:33:47 -0000	1.5
  @@ -1,9 +1,7 @@
  -package org.apache.commons.io.filefilter;
  -
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -54,52 +52,79 @@
    * <http://www.apache.org/>.
    *
    */
  +package org.apache.commons.io.filefilter;
   
  -import java.io.FilenameFilter;
  -import java.io.FileFilter;
   import java.io.File;
  +import java.io.FileFilter;
  +import java.io.FilenameFilter;
   
   /**
  - * This is used to turn a JDK FileFilter or FilenameFilter into a Predicate, 
  - * as well as an Apache IO FileFilter. Once it is a predicate, it can be 
  - * used with the PredicateUtils.
  + * This class turns a Java FileFilter or FilenameFilter into an IO FileFilter.
  + * 
  + * @since Commons IO 1.0
  + * @version $Revision$ $Date$
  + * 
  + * @author Henri Yandell
  + * @author Stephen Colebourne
    */
  -public class DelegateFileFilter
  -extends AbstractFileFilter
  -{
  -
  -    private FilenameFilter filename;
  -    private java.io.FileFilter file;
  +public class DelegateFileFilter extends AbstractFileFilter {
   
  +    /** The Filename filter */
  +    private FilenameFilter filenameFilter;
  +    /** The File filter */
  +    private FileFilter fileFilter;
  +
  +    /**
  +     * Constructs a delegate file filter around an existing FilenameFilter.
  +     * 
  +     * @param filter  the filter to decorate
  +     */
       public DelegateFileFilter(FilenameFilter filter) {
  -        if(filter == null) {
  -            throw new NullPointerException("Setting a filter to null will "+
  -                "infinitely loop. Use a NullFileFilter instead. ");
  +        if (filter == null) {
  +            throw new IllegalArgumentException("The FilenameFilter must not be null");
           }
  -        this.filename = filter;
  +        this.filenameFilter = filter;
       }
   
  -    public DelegateFileFilter(java.io.FileFilter filter) {
  -        if(filter == null) {
  -            throw new NullPointerException("Setting a filter to null will "+
  -                "infinitely loop. Use a NullFileFilter instead. ");
  +    /**
  +     * Constructs a delegate file filter around an existing FileFilter.
  +     * 
  +     * @param filter  the filter to decorate
  +     */
  +    public DelegateFileFilter(FileFilter filter) {
  +        if (filter == null) {
  +            throw new IllegalArgumentException("The FileFilter must not be null");
           }
  -        this.file = filter;
  +        this.fileFilter = filter;
       }
   
  -    public boolean accept( File f) {
  -        if(file != null) {
  -            return file.accept(f);
  +    /**
  +     * Checks the filter.
  +     * 
  +     * @param file  the file to check
  +     * @return true if the filter matches
  +     */
  +    public boolean accept(File file) {
  +        if (fileFilter != null) {
  +            return fileFilter.accept(file);
           } else {
  -            return super.accept(f);
  +            return super.accept(file);
           }
       }
   
  -    public boolean accept( File dir, String name) {
  -        if(filename != null) {
  -            return filename.accept(dir, name);
  +    /**
  +     * Checks the filter.
  +     * 
  +     * @param dir  the directory
  +     * @param name  the filename in the directory
  +     * @return true if the filter matches
  +     */
  +    public boolean accept(File dir, String name) {
  +        if (filenameFilter != null) {
  +            return filenameFilter.accept(dir, name);
           } else {
               return super.accept(dir, name);
           }
       }
  +    
   }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/TrueFileFilter.java
  
  Index: TrueFileFilter.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.io.filefilter;
  
  import java.io.File;
  
  /**
   * A file filter that always returns true.
   * 
   * @since Commons IO 1.0
   * @version $Revision: 1.1 $ $Date: 2003/05/16 22:33:46 $
   * 
   * @author Henri Yandell
   * @author Stephen Colebourne
   */
  public class TrueFileFilter implements IOFileFilter {
      
      /** Singleton instance of true filter */
      public static final IOFileFilter INSTANCE = new TrueFileFilter();
      
      /**
       * Restrictive consructor.
       */
      protected TrueFileFilter() {
      }
      
      /**
       * Return true.
       * 
       * @param file  the file to check
       * @return true
       */
      public boolean accept(File file) {
          return true;
      }
      
      /**
       * Return true.
       * 
       * @param dir  the directory to check
       * @param name  the filename
       * @return true
       */
      public boolean accept(File dir, String name) {
          return true;
      }
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/SuffixFileFilter.java
  
  Index: SuffixFileFilter.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.io.filefilter;
  
  import java.io.File;
  import java.util.List;
  
  /**
   * This filters files based on the suffix (what the filename
   * ends with). This is used in retrieving all the files of a
   * particular type.
   * <p>
   * For example, to retrieve and print all <code>*.java</code> files 
   * in the current directory:
   *
   * <pre>
   * File dir = new File(".");
   * String[] files = dir.list( new SuffixFileFilter( new String[]{".java"} ) );
   * for (int i = 0; i &lt; files.length; i++) {
   *     System.out.println(files[i]);
   * }
   * </pre>
   *
   * @since Commons IO 1.0
   * @version $Revision: 1.1 $ $Date: 2003/05/16 22:33:46 $
   * 
   * @author Henri Yandell
   * @author Stephen Colebourne
   * @author Federico Barbieri
   * @author Serge Knystautas
   * @author Peter Donald
   */
  public class SuffixFileFilter extends AbstractFileFilter {
      
      /** The filename suffixes to search for */
      private final String[] suffixes;
  
      /**
       * Constructs a new Suffix file filter for a single extension.
       * 
       * @param extension  the extension to allow, must not be null
       */
      public SuffixFileFilter(final String suffix) {
          if (suffix == null) {
              throw new IllegalArgumentException("The suffix must not be null");
          }
          this.suffixes = new String[] {suffix};
      }
  
      /**
       * Constructs a new Suffix file filter for an array of suffixs.
       * <p>
       * The array is not cloned, so could be changed after constructing the
       * instance. This would be inadvisable however.
       * 
       * @param suffixes  the suffixes to allow, must not be null
       */
      public SuffixFileFilter(final String[] suffixes) {
          if (suffixes == null) {
              throw new IllegalArgumentException("The array of suffixes must not be null");
          }
          this.suffixes = suffixes;
      }
  
      /**
       * Constructs a new Suffix file filter for a list of suffixes.
       * 
       * @param suffixes  the suffixes to allow, must not be null
       */
      public SuffixFileFilter(final List suffixes) {
          if (suffixes == null) {
              throw new IllegalArgumentException("The list of suffixes must not be null");
          }
          this.suffixes = (String[]) suffixes.toArray(new String[suffixes.size()]);
      }
  
      /**
       * Checks to see if the filename ends with the suffix.
       * 
       * @param file  the File to check
       * @return true if the filename ends with one of our suffixes
       */
      public boolean accept(final File file) {
          String name = file.getName();
          for (int i = 0; i < this.suffixes.length; i++) {
              if (name.endsWith(this.suffixes[i])) {
                  return true;
              }
          }
          return false;
      }
      
      /**
       * Checks to see if the filename ends with the suffix.
       * 
       * @param file  the File directory
       * @param name  the filename
       * @return true if the filename ends with one of our suffixes
       */
      public boolean accept(final File file, final String name) {
          for (int i = 0; i < this.suffixes.length; i++) {
              if (name.endsWith(this.suffixes[i])) {
                  return true;
              }
          }
          return false;
      }
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/FalseFileFilter.java
  
  Index: FalseFileFilter.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.io.filefilter;
  
  import java.io.File;
  
  /**
   * A file filter that always returns false.
   * 
   * @since Commons IO 1.0
   * @version $Revision: 1.1 $ $Date: 2003/05/16 22:33:47 $
   * 
   * @author Henri Yandell
   * @author Stephen Colebourne
   */
  public class FalseFileFilter implements IOFileFilter {
      
      /** Singleton instance of false filter */
      public static final IOFileFilter INSTANCE = new FalseFileFilter();
      
      /**
       * Restrictive consructor.
       */
      protected FalseFileFilter() {
      }
      
      /**
       * Return false.
       * 
       * @param file  the file to check
       * @return false
       */
      public boolean accept(File file) {
          return false;
      }
      
      /**
       * Return false.
       * 
       * @param dir  the directory to check
       * @param name  the filename
       * @return false
       */
      public boolean accept(File dir, String name) {
          return false;
      }
      
  }
  
  
  
  1.3       +46 -38    jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/AndFileFilter.java
  
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/NotFileFilter.java
  
  Index: NotFileFilter.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.io.filefilter;
  
  import java.io.File;
  
  /**
   * This filter produces a logical NOT of the filters specified.
   *
   * @since Commons IO 1.0
   * @version $Revision: 1.1 $ $Date: 2003/05/16 22:33:47 $
   * 
   * @author Stephen Colebourne
   */
  public class NotFileFilter extends AbstractFileFilter {
      
      /** The filter */
      private final IOFileFilter filter;
  
      /**
       * Constructs a new file filter that NOTs the result of another filters.
       * 
       * @param filter  the filter
       */
      public NotFileFilter(IOFileFilter filter) {
          if (filter == null) {
              throw new IllegalArgumentException("The filter must not be null");
          }
          this.filter = filter;
      }
  
      /**
       * Checks to see if both filters are true.
       * 
       * @param file  the File to check
       * @return true if the filter returns false
       */
      public boolean accept(File file) {
          return ! filter.accept(file);
      }
      
      /**
       * Checks to see if both filters are true.
       * 
       * @param file  the File directory
       * @param name  the filename
       * @return true if the filter returns false
       */
      public boolean accept(final File file, final String name) {
          return ! filter.accept(file, name);
      }
      
  }
  
  
  
  1.3       +46 -39    jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/OrFileFilter.java
  
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/IOFileFilter.java
  
  Index: IOFileFilter.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.io.filefilter;
  
  import java.io.File;
  import java.io.FileFilter;
  import java.io.FilenameFilter;
  
  /**
   * An interface which brings the FileFilter and FilenameFilter 
   * interfaces together.
   * 
   * @since Commons IO 1.0
   * @version $Revision: 1.1 $ $Date: 2003/05/16 22:33:47 $
   * 
   * @author Henri Yandell
   * @author Stephen Colebourne
   */
  public interface IOFileFilter extends FileFilter, FilenameFilter {
  
      /**
       * Checks to see if the File should be accepted by this filter.
       * <p>
       * Defined in {@link java.io.FileFilter}.
       * 
       * @param file  the File to check
       * @return true if this file matches the test
       */
      public boolean accept(File file);
  
      /**
       * Checks to see if the File should be accepted by this filter.
       * <p>
       * Defined in {@link java.io.FilenameFilter}.
       * 
       * @param file  the directory File to check
       * @param name  the filename within the directory to check
       * @return true if this file matches the test
       */
      public boolean accept(File dir, String name);
      
  }
  
  
  

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