commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r982447 - in /commons/proper/io/trunk/src: java/org/apache/commons/io/filefilter/FileFilterUtils.java test/org/apache/commons/io/filefilter/FileFilterTestCase.java
Date Thu, 05 Aug 2010 00:52:58 GMT
Author: niallp
Date: Thu Aug  5 00:52:57 2010
New Revision: 982447

URL: http://svn.apache.org/viewvc?rev=982447&view=rev
Log:
IO-232 Add Case Sensitive Creation Methods to FileFilterUtils - thanks to Michael Wooten for
the patch

Modified:
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java
    commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java?rev=982447&r1=982446&r2=982447&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java
Thu Aug  5 00:52:57 2010
@@ -100,6 +100,18 @@ public class FileFilterUtils {
     }
 
     /**
+     * Returns a filter that returns true if the filename matches the specified text.
+     * 
+     * @param name  the filename
+     * @param caseSensitivity  how to handle case sensitivity, null means case-sensitive
+     * @return a name checking filter
+     * @since Commons IO 2.0
+     */
+    public static IOFileFilter nameFileFilter(String name, IOCase caseSensitivity) {
+        return new NameFileFilter(name, caseSensitivity);
+    }
+
+    /**
      * Returns a filter that checks if the file is a directory.
      * 
      * @return file filter that accepts only directories and not files
@@ -384,7 +396,7 @@ public class FileFilterUtils {
             andFileFilter(directoryFileFilter(), nameFileFilter("CVS")));;
 
     /* Constructed on demand and then cached */
-    private static final IOFileFilter svnFilter = svnFilter = notFileFilter(
+    private static final IOFileFilter svnFilter = notFileFilter(
             andFileFilter(directoryFileFilter(), nameFileFilter(".svn")));
 
     /**

Modified: commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java?rev=982447&r1=982446&r2=982447&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
(original)
+++ commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
Thu Aug  5 00:52:57 2010
@@ -160,6 +160,17 @@ public class FileFilterTestCase extends 
             fail();
         } catch (IllegalArgumentException ex) {
         }
+        
+        // FileFilterUtils.suffixFileFilter(String, IOCase) tests
+        filter = FileFilterUtils.suffixFileFilter("est", IOCase.INSENSITIVE);
+        assertFiltering(filter, new File("test"), true);
+        assertFiltering(filter, new File("TEST"), true);
+        
+        try {
+            FileFilterUtils.suffixFileFilter((String) null, IOCase.INSENSITIVE);
+            fail();
+        } catch (IllegalArgumentException ex) {
+        }
     }
 
     public void testDirectory() throws Exception {
@@ -282,6 +293,19 @@ public class FileFilterTestCase extends 
             fail();
         } catch (IllegalArgumentException ex) {
         }
+        
+        // FileFilterUtils.prefixFileFilter(String, IOCase) tests
+        filter = FileFilterUtils.prefixFileFilter("bar", IOCase.INSENSITIVE);
+        assertFiltering(filter, new File("foo.test2"), false);
+        assertFiltering(filter, new File("bar.test2"), true);
+        assertFiltering(filter, new File("FOO.test2"), false); //case-sensitive
+        assertFiltering(filter, new File("BAR.test2"), true);  //case-sensitive
+        
+        try {
+            FileFilterUtils.prefixFileFilter((String) null, IOCase.INSENSITIVE);
+            fail();
+        } catch (IllegalArgumentException ex) {
+        }
     }
 
     public void testNameFilter() throws Exception {
@@ -329,6 +353,14 @@ public class FileFilterTestCase extends 
         assertFiltering(filter, new File("barfoo"), false);
         assertFiltering(filter, new File("foobar"), false);
         assertFiltering(filter, new File("fred"), false);
+        
+        // FileFilterUtils.nameFileFilter(String, IOCase) tests
+        filter = FileFilterUtils.nameFileFilter("foo", IOCase.INSENSITIVE);
+        assertFiltering(filter, new File("foo"), true);
+        assertFiltering(filter, new File("FOO"), true); //case-insensitive
+        assertFiltering(filter, new File("barfoo"), false);
+        assertFiltering(filter, new File("foobar"), false);
+        assertFiltering(filter, new File("fred"), false);
     }
 
     public void testNameFilterNullArgument() throws Exception {
@@ -338,6 +370,12 @@ public class FileFilterTestCase extends 
             fail( "constructing a NameFileFilter with a null String argument should fail.");
         } catch( IllegalArgumentException iae ) {
         }
+        
+        try {
+            FileFilterUtils.nameFileFilter(test, IOCase.INSENSITIVE);
+            fail( "constructing a NameFileFilter with a null String argument should fail.");
+        } catch( IllegalArgumentException iae ) {
+        }
     }
 
     public void testNameFilterNullArrayArgument() throws Exception {



Mime
View raw message