commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r417092 - in /jakarta/commons/proper/io/trunk: RELEASE-NOTES.txt src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java src/java/org/apache/commons/io/filefilter/WildcardFilter.java
Date Sun, 25 Jun 2006 23:19:58 GMT
Author: scolebourne
Date: Sun Jun 25 16:19:58 2006
New Revision: 417092

URL: http://svn.apache.org/viewvc?rev=417092&view=rev
Log:
Add WildcardFileFilter deprecating WildcardFilter

Added:
    jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
  (with props)
Modified:
    jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt
    jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java

Modified: jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt?rev=417092&r1=417091&r2=417092&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt (original)
+++ jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt Sun Jun 25 16:19:58 2006
@@ -26,6 +26,8 @@
 
 Deprecations from 1.2
 ---------------------
+- WildcardFilter deprecated, replaced by WildcardFileFilter
+  - old class only accepted files, thus had a confusing dual purpose
 
 
 Bug fixes from 1.2
@@ -36,6 +38,18 @@
 
 Enhancements from 1.2
 ---------------------
+- IOCase
+  - New class/enumeration for case-sensitivity control
+
+- FilenameUtils
+  - New methods to handle case-sensitivity
+  - wildcardMatch - new method that has IOCase as a parameter
+  - equals - new method that has IOCase as a parameter
+
+- WildcardFileFilter
+  - Replacement for WildcardFilter
+  - Accepts both files and directories
+  - Ability to control case-sensitivity
 
 
 Feedback

Added: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java?rev=417092&view=auto
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
(added)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
Sun Jun 25 16:19:58 2006
@@ -0,0 +1,152 @@
+package org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOCase;
+
+/**
+ * Filters files using the supplied wildcards.
+ * <p>
+ * This filter selects files and directories based on one or more wildcards.
+ * Testing is case-sensitive by default, but this can be configured.
+ * <p>
+ * The wildcard matcher uses the characters '?' and '*' to represent a
+ * single or multiple wildcard characters.
+ * This is the same as often found on Dos/Unix command lines.
+ * The extension check is case-sensitive by .
+ * See {@link FilenameUtils#wildcardMatchOnSystem} for more information.
+ * <p>
+ * For example:
+ * <pre>
+ * File dir = new File(".");
+ * FileFilter fileFilter = new WildcardFileFilter("*test*.java~*~");
+ * File[] files = dir.listFiles(fileFilter);
+ * for (int i = 0; i < files.length; i++) {
+ *   System.out.println(files[i]);
+ * }
+ * </pre>
+ *
+ * @author Jason Anderson
+ * @version $Revision: 155419 $ $Date$
+ * @since Commons IO 1.3
+ */
+public class WildcardFileFilter extends AbstractFileFilter {
+
+    /** The wildcards that will be used to match filenames. */
+    private String[] wildcards;
+    /** Whether the comparison is case sensitive. */
+    private IOCase caseSensitivity;
+
+    /**
+     * Construct a new case-sensitive wildcard filter for a single wildcard.
+     *
+     * @param wildcard  the wildcard to match
+     * @throws IllegalArgumentException if the pattern is null
+     */
+    public WildcardFileFilter(String wildcard) {
+        this(wildcard, null);
+    }
+
+    /**
+     * Construct a new wildcard filter for a single wildcard specifying case-sensitivity.
+     *
+     * @param wildcard  the wildcard to match, not null
+     * @param caseSensitivity  how to handle case sensitivity, null means case-sensitive
+     * @throws IllegalArgumentException if the pattern is null
+     */
+    public WildcardFileFilter(String wildcard, IOCase caseSensitivity) {
+        if (wildcard == null) {
+            throw new IllegalArgumentException("The wildcard must not be null");
+        }
+        this.wildcards = new String[] { wildcard };
+        this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
+    }
+
+    /**
+     * Construct a new case-sensitive wildcard filter for an array of wildcards.
+     *
+     * @param wildcards  the array of wildcards to match
+     * @throws IllegalArgumentException if the pattern array is null
+     */
+    public WildcardFileFilter(String[] wildcards) {
+        this(wildcards, null);
+    }
+
+    /**
+     * Construct a new wildcard filter for an array of wildcards specifying case-sensitivity.
+     *
+     * @param wildcards  the array of wildcards to match, not null
+     * @param caseSensitivity  how to handle case sensitivity, null means case-sensitive
+     * @throws IllegalArgumentException if the pattern array is null
+     */
+    public WildcardFileFilter(String[] wildcards, IOCase caseSensitivity) {
+        if (wildcards == null) {
+            throw new IllegalArgumentException("The wildcard array must not be null");
+        }
+        this.wildcards = wildcards;
+        this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
+    }
+
+    /**
+     * Construct a new case-sensitive wildcard filter for a list of wildcards.
+     *
+     * @param wildcards  the list of wildcards to match, not null
+     * @throws IllegalArgumentException if the pattern list is null
+     * @throws ClassCastException if the list does not contain Strings
+     */
+    public WildcardFileFilter(List wildcards) {
+        this(wildcards, null);
+    }
+
+    /**
+     * Construct a new wildcard filter for a list of wildcards specifying case-sensitivity.
+     *
+     * @param wildcards  the list of wildcards to match, not null
+     * @param caseSensitivity  how to handle case sensitivity, null means case-sensitive
+     * @throws IllegalArgumentException if the pattern list is null
+     * @throws ClassCastException if the list does not contain Strings
+     */
+    public WildcardFileFilter(List wildcards, IOCase caseSensitivity) {
+        if (wildcards == null) {
+            throw new IllegalArgumentException("The wildcard list must not be null");
+        }
+        this.wildcards = (String[]) wildcards.toArray(new String[wildcards.size()]);
+        this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Checks to see if the filename matches one of the wildcards.
+     *
+     * @param dir  the file directory
+     * @param name  the filename
+     * @return true if the filename matches one of the wildcards
+     */
+    public boolean accept(File dir, String name) {
+        for (int i = 0; i < wildcards.length; i++) {
+            if (FilenameUtils.wildcardMatch(name, wildcards[i], caseSensitivity)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Checks to see if the filename matches one of the wildcards.
+     *
+     * @param file  the file to check
+     * @return true if the filename matches one of the wildcards
+     */
+    public boolean accept(File file) {
+        String name = file.getName();
+        for (int i = 0; i < wildcards.length; i++) {
+            if (FilenameUtils.wildcardMatch(name, wildcards[i], caseSensitivity)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

Propchange: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
------------------------------------------------------------------------------
    svn:keywords = "author date id revision"

Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java?rev=417092&r1=417091&r2=417092&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java
(original)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java
Sun Jun 25 16:19:58 2006
@@ -2,16 +2,22 @@
 
 import java.io.File;
 import java.util.List;
+
 import org.apache.commons.io.FilenameUtils;
 
 /**
- * Filters files using supplied wildcard(s).
- * <p/>
- * See org.apache.commons.io.find.FilenameUtils.wildcardMatch() for wildcard matching rules
- * <p/>
- *
- * <p/>
- * e.g.
+ * Filters files using the supplied wildcards.
+ * <p>
+ * This filter selects files, but not directories, based on one or more wildcards
+ * and using case-sensitive comparison.
+ * <p>
+ * The wildcard matcher uses the characters '?' and '*' to represent a
+ * single or multiple wildcard characters.
+ * This is the same as often found on Dos/Unix command lines.
+ * The extension check is case-sensitive.
+ * See {@link FilenameUtils#wildcardMatch} for more information.
+ * <p>
+ * For example:
  * <pre>
  * File dir = new File(".");
  * FileFilter fileFilter = new WildcardFilter("*test*.java~*~");
@@ -24,59 +30,59 @@
  * @author Jason Anderson
  * @version $Revision$ $Date$
  * @since Commons IO 1.1
+ * @deprecated Use WilcardFileFilter. Deprecated as this class performs directory
+ * filtering which it shouldn't do, but that can't be removed due to compatability.
  */
 public class WildcardFilter extends AbstractFileFilter {
 
-    /** The wildcards that will be used to match filenames */
-    private String[] wildcards = null;
+    /** The wildcards that will be used to match filenames. */
+    private String[] wildcards;
 
     /**
-     * Construct a new wildcard filter for a single wildcard
+     * Construct a new case-sensitive wildcard filter for a single wildcard.
      *
-     * @param wildcard wildcard to match
+     * @param wildcard  the wildcard to match
      * @throws IllegalArgumentException if the pattern is null
      */
     public WildcardFilter(String wildcard) {
         if (wildcard == null) {
-            throw new java.lang.IllegalArgumentException();
+            throw new IllegalArgumentException("The wildcard must not be null");
         }
-    
-        wildcards = new String[] { wildcard };
+        this.wildcards = new String[] { wildcard };
     }
 
     /**
-     * Construct a new wildcard filter for an array of wildcards
+     * Construct a new case-sensitive wildcard filter for an array of wildcards.
      *
-     * @param wildcards wildcards to match
+     * @param wildcards  the array of wildcards to match
      * @throws IllegalArgumentException if the pattern array is null
      */
     public WildcardFilter(String[] wildcards) {
         if (wildcards == null) {
-            throw new java.lang.IllegalArgumentException();
+            throw new IllegalArgumentException("The wildcard array must not be null");
         }
-    
         this.wildcards = wildcards;
     }
 
     /**
-     * Construct a new wildcard filter for a list of wildcards
+     * Construct a new case-sensitive wildcard filter for a list of wildcards.
      *
-     * @param wildcards list of wildcards to match
+     * @param wildcards  the list of wildcards to match
      * @throws IllegalArgumentException if the pattern list is null
      * @throws ClassCastException if the list does not contain Strings
      */
     public WildcardFilter(List wildcards) {
         if (wildcards == null) {
-            throw new java.lang.IllegalArgumentException();
+            throw new IllegalArgumentException("The wildcard list must not be null");
         }
-    
         this.wildcards = (String[]) wildcards.toArray(new String[wildcards.size()]);
     }
 
+    //-----------------------------------------------------------------------
     /**
      * Checks to see if the filename matches one of the wildcards.
      *
-     * @param dir   the file directory
+     * @param dir  the file directory
      * @param name  the filename
      * @return true if the filename matches one of the wildcards
      */
@@ -84,13 +90,13 @@
         if (dir != null && new File(dir, name).isDirectory()) {
             return false;
         }
-    
+        
         for (int i = 0; i < wildcards.length; i++) {
             if (FilenameUtils.wildcardMatch(name, wildcards[i])) {
                 return true;
             }
         }
-    
+        
         return false;
     }
 
@@ -104,13 +110,13 @@
         if (file.isDirectory()) {
             return false;
         }
-    
+        
         for (int i = 0; i < wildcards.length; i++) {
             if (FilenameUtils.wildcardMatch(file.getName(), wildcards[i])) {
                 return true;
             }
         }
-    
+        
         return false;
     }
 



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