commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r463940 - in /jakarta/commons/proper/io/trunk: RELEASE-NOTES.txt src/java/org/apache/commons/io/filefilter/FileFilterUtils.java src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
Date Sat, 14 Oct 2006 14:20:27 GMT
Author: scolebourne
Date: Sat Oct 14 07:20:25 2006
New Revision: 463940

URL: http://svn.apache.org/viewvc?view=rev&rev=463940
Log:
FileFilterUtils.makeDirectoryOnly/makeFileOnly
- two new methods that decorate a file filter to make it apply to directories only or files
only

Modified:
    jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt
    jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java

Modified: jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt?view=diff&rev=463940&r1=463939&r2=463940
==============================================================================
--- jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt (original)
+++ jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt Sat Oct 14 07:20:25 2006
@@ -139,9 +139,13 @@
     (whereas if everything uses INSTANCE, then they just clash)
   - The old INSTANCE constants are still present and have not been deprecated
 
-- FileFilterUtils
+- FileFilterUtils.sizeRangeFileFilter
   - new sizeRangeFileFilter(long minimumSize, long maximumSize) method which 
     creates a filter that accepts files within the specified size range.
+
+- FileFilterUtils.makeDirectoryOnly/makeFileOnly
+  - two new methods that decorate a file filter to make it apply to
+    directories only or files only
 
 - NullWriter
   - New writer that acts as a sink for all data, as per /dev/null

Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java?view=diff&rev=463940&r1=463939&r2=463940
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java
(original)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java
Sat Oct 14 07:20:25 2006
@@ -218,7 +218,6 @@
     }
 
     //-----------------------------------------------------------------------
-
     /**
      * Returns a filter that returns true if the file was last modified after
      * the specified cutoff time.
@@ -330,6 +329,35 @@
         IOFileFilter minimumFilter = new SizeFileFilter(minSizeInclusive, true);
         IOFileFilter maximumFilter = new SizeFileFilter(maxSizeInclusive + 1L, false);
         return new AndFileFilter(minimumFilter, maximumFilter);
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Decorates a filter so that it only applies to directories and not to files.
+     * 
+     * @param filter  the filter to decorate, null means an unrestricted filter
+     * @return the decorated filter, never null
+     * @since 1.3
+     */
+    public static IOFileFilter makeDirectoryOnly(IOFileFilter filter) {
+        if (filter == null) {
+            return DirectoryFileFilter.DIRECTORY;
+        }
+        return new AndFileFilter(DirectoryFileFilter.DIRECTORY, filter);
+    }
+
+    /**
+     * Decorates a filter so that it only applies to files and not to directories.
+     * 
+     * @param filter  the filter to decorate, null means an unrestricted filter
+     * @return the decorated filter, never null
+     * @since 1.3
+     */
+    public static IOFileFilter makeFileOnly(IOFileFilter filter) {
+        if (filter == null) {
+            return FileFileFilter.FILE;
+        }
+        return new AndFileFilter(FileFileFilter.FILE, filter);
     }
 
 }

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java?view=diff&rev=463940&r1=463939&r2=463940
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
(original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
Sat Oct 14 07:20:25 2006
@@ -736,5 +736,62 @@
         FileUtils.forceDelete(emptyDir);
     }
 
+    //-----------------------------------------------------------------------
+    public void testMakeDirectoryOnly() throws Exception {
+        assertSame(DirectoryFileFilter.DIRECTORY, FileFilterUtils.makeDirectoryOnly(null));
+        
+        IOFileFilter filter = FileFilterUtils.makeDirectoryOnly(
+                FileFilterUtils.nameFileFilter("B"));
+        
+        File fileA = new File(getTestDirectory(), "A");
+        File fileB = new File(getTestDirectory(), "B");
+        
+        fileA.mkdirs();
+        fileB.mkdirs();
+        
+        assertFiltering(filter, fileA, false);
+        assertFiltering(filter, fileB, true);
+        
+        FileUtils.deleteDirectory(fileA);
+        FileUtils.deleteDirectory(fileB);
+        
+        createFile(fileA, 32);
+        createFile(fileB, 32);
+        
+        assertFiltering(filter, fileA, false);
+        assertFiltering(filter, fileB, false);
+        
+        fileA.delete();
+        fileB.delete();
+    }
+         
+    //-----------------------------------------------------------------------
+    public void testMakeFileOnly() throws Exception {
+        assertSame(FileFileFilter.FILE, FileFilterUtils.makeFileOnly(null));
+        
+        IOFileFilter filter = FileFilterUtils.makeFileOnly(
+                FileFilterUtils.nameFileFilter("B"));
+        
+        File fileA = new File(getTestDirectory(), "A");
+        File fileB = new File(getTestDirectory(), "B");
+        
+        fileA.mkdirs();
+        fileB.mkdirs();
+        
+        assertFiltering(filter, fileA, false);
+        assertFiltering(filter, fileB, false);
+        
+        FileUtils.deleteDirectory(fileA);
+        FileUtils.deleteDirectory(fileB);
+        
+        createFile(fileA, 32);
+        createFile(fileB, 32);
+        
+        assertFiltering(filter, fileA, false);
+        assertFiltering(filter, fileB, true);
+        
+        fileA.delete();
+        fileB.delete();
+    }
+         
 }
-



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


Mime
View raw message