commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r424885 - in /jakarta/commons/proper/io/trunk/src: java/org/apache/commons/io/filefilter/FileFilterUtils.java test/org/apache/commons/io/filefilter/FileFilterTestCase.java
Date Mon, 24 Jul 2006 02:46:05 GMT
Author: niallp
Date: Sun Jul 23 19:46:05 2006
New Revision: 424885

URL: http://svn.apache.org/viewvc?rev=424885&view=rev
Log:
IO-87 - Provide a convenience mehod in FileFilterUtils to create a Size Range filter

Modified:
    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/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?rev=424885&r1=424884&r2=424885&view=diff
==============================================================================
--- 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
Sun Jul 23 19:46:05 2006
@@ -316,4 +316,19 @@
         return new SizeFileFilter(threshold, acceptLarger);
     }
 
+    /**
+     * Returns a filter that returns true if the file size is within
+     * the specified range.
+     *
+     * @param minimumSize the minimum file size
+     * @param maximumSize the maximum file size
+     * @return an appropriately configured IOFileFilter
+     * @since Commons IO 1.3
+     */
+    public static IOFileFilter sizeFileFilter(long minimumSize, long maximumSize) {
+        IOFileFilter minimumFilter = new SizeFileFilter(minimumSize, true);
+        IOFileFilter maximumFilter = new SizeFileFilter(maximumSize + 1L, false);
+        return new AndFileFilter(minimumFilter, maximumFilter);
+    }
+
 }

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?rev=424885&r1=424884&r2=424885&view=diff
==============================================================================
--- 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
Sun Jul 23 19:46:05 2006
@@ -636,6 +636,23 @@
         assertFiltering(filter2, largeFile, true);
         assertFiltering(filter3, largeFile, false);
 
+        // size range tests
+        IOFileFilter filter4 = FileFilterUtils.sizeFileFilter(33, 127);
+        IOFileFilter filter5 = FileFilterUtils.sizeFileFilter(32, 127);
+        IOFileFilter filter6 = FileFilterUtils.sizeFileFilter(33, 128);
+        IOFileFilter filter7 = FileFilterUtils.sizeFileFilter(31, 129);
+        IOFileFilter filter8 = FileFilterUtils.sizeFileFilter(128, 128);
+
+        assertFiltering(filter4, smallFile, false);
+        assertFiltering(filter4, largeFile, false);
+        assertFiltering(filter5, smallFile, true);
+        assertFiltering(filter5, largeFile, false);
+        assertFiltering(filter6, smallFile, false);
+        assertFiltering(filter6, largeFile, true);
+        assertFiltering(filter7, smallFile, true);
+        assertFiltering(filter7, largeFile, true);
+        assertFiltering(filter8, largeFile, true);
+
         try {
             FileFilterUtils.sizeFileFilter(-1);
             fail();



---------------------------------------------------------------------
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