commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject cvs commit: jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter FileFilterUtils.java PredicateFileFilter.java AbstractFileFilter.java DelegateFileFilter.java FileFilter.java
Date Sat, 07 Dec 2002 20:29:25 GMT
bayard      2002/12/07 12:29:25

  Modified:    io/src/java/org/apache/commons/io/filefilter
                        AbstractFileFilter.java DelegateFileFilter.java
                        FileFilter.java
  Added:       io/src/java/org/apache/commons/io/filefilter
                        FileFilterUtils.java PredicateFileFilter.java
  Log:
  Now FileFilter's are Predicates. Thus new classes.
  
  Revision  Changes    Path
  1.4       +10 -1     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractFileFilter.java	28 Jul 2002 03:18:43 -0000	1.3
  +++ AbstractFileFilter.java	7 Dec 2002 20:29:24 -0000	1.4
  @@ -58,16 +58,24 @@
   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.
  + *
    */
   public abstract class AbstractFileFilter
   implements FileFilter
   {
   
  +    /** Defined in Predicate */
  +    public boolean evaluate(Object object) {
  +        return accept( (File)object );
  +    }
  +
       /** Defined in FileFilter */
       public boolean accept( File f) {
           return accept( f.getParentFile(), f.getName());
  @@ -75,6 +83,7 @@
   
       /** Defined in FilenameFilter */
       public boolean accept( File dir, String name) {
  -        return accept( new File( dir.getName() + name ) );
  +        return accept( new File( dir.getName() + File.separator + name ) );
       }
  +
   }
  
  
  
  1.4       +3 -0      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DelegateFileFilter.java	28 Jul 2002 03:18:43 -0000	1.3
  +++ DelegateFileFilter.java	7 Dec 2002 20:29:24 -0000	1.4
  @@ -60,6 +60,9 @@
   import java.io.File;
   
   /**
  + * 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.
    */
   public class DelegateFileFilter
   extends AbstractFileFilter
  
  
  
  1.4       +3 -1      jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/FileFilter.java
  
  Index: FileFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/FileFilter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileFilter.java	28 Jul 2002 03:18:43 -0000	1.3
  +++ FileFilter.java	7 Dec 2002 20:29:24 -0000	1.4
  @@ -58,12 +58,14 @@
   import java.io.FilenameFilter;
   import java.io.File;
   
  +import org.apache.commons.lang.functor.Predicate;
  +
   /**
    * An interface which brings the FileFilter and FilenameFilter 
    * interfaces together.
    */
   public interface FileFilter
  -extends java.io.FileFilter, FilenameFilter
  +extends java.io.FileFilter, FilenameFilter, Predicate
   {
   
       /** Defined in java.io.FileFilter */
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java
  
  Index: FileFilterUtils.java
  ===================================================================
  package org.apache.commons.io.filefilter;
  
  import org.apache.commons.lang.functor.Predicate;
  import org.apache.commons.lang.functor.PredicateUtils;
  
  public class FileFilterUtils {
  
      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 ) 
              );
      }
  
      static public FileFilter nullFileFilter() {
          return predicateToFileFilter( PredicateUtils.nullPredicate() );
      }
  
      static public FileFilter notFileFilter(FileFilter f) {
          return predicateToFileFilter( PredicateUtils.notPredicate( f ) );
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/io/src/java/org/apache/commons/io/filefilter/PredicateFileFilter.java
  
  Index: PredicateFileFilter.java
  ===================================================================
  package org.apache.commons.io.filefilter;
  
  import java.io.File;
  
  import org.apache.commons.lang.functor.Predicate;
  
  /**
   * PredicateFileFilter is a FileFilter built on top of a Predicate.
   * This is essential for when lang.functor.PredicateUtils is used to 
   * create an AndPredicate around two FileFilters, and we need to treat 
   * that AndPredicate in a FileFilter way, for example, to pass to listFiles.
   */
  public class PredicateFileFilter extends AbstractFileFilter {
  
      private Predicate predicate;
  
      public PredicateFileFilter(Predicate predicate) {
          this.predicate = predicate;
      }
  
      public boolean accept( File f ) {
          return this.predicate.evaluate( f );
      }
  
  }
  
  
  

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


Mime
View raw message