You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ni...@apache.org on 2007/11/01 16:47:06 UTC

svn commit: r591058 - in /commons/proper/io/trunk: ./ src/java/org/apache/commons/io/filefilter/

Author: niallp
Date: Thu Nov  1 08:47:05 2007
New Revision: 591058

URL: http://svn.apache.org/viewvc?rev=591058&view=rev
Log:
IO-133 - Make fields final so classes are immutable/threadsafe - thanks to Sebb for the patch

Modified:
    commons/proper/io/trunk/RELEASE-NOTES.txt
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/AgeFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/DelegateFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NameFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NotFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/RegexFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SizeFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SuffixFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java

Modified: commons/proper/io/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/RELEASE-NOTES.txt?rev=591058&r1=591057&r2=591058&view=diff
==============================================================================
--- commons/proper/io/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/io/trunk/RELEASE-NOTES.txt Thu Nov  1 08:47:05 2007
@@ -56,6 +56,9 @@
 
 - Make IOFileFilter implementations Serializable [IO-131]
 
+- Make fields final so classes are immutable/threadsafe [IO-133]
+  - changes to Age, Delegate, Name, Not, Prefix, Regex, Size, Suffix and Wildcard IOFileFilter
+    implementations.
 
 Feedback
 --------

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/AgeFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/AgeFileFilter.java?rev=591058&r1=591057&r2=591058&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/AgeFileFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/AgeFileFilter.java Thu Nov  1 08:47:05 2007
@@ -46,9 +46,9 @@
 public class AgeFileFilter extends AbstractFileFilter implements Serializable {
 
     /** The cutoff time threshold. */
-    private long cutoff;
+    private final long cutoff;
     /** Whether the files accepted will be older or newer. */
-    private boolean acceptOlder;
+    private final boolean acceptOlder;
 
     /**
      * Constructs a new age file filter for files equal to or older than

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/DelegateFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/DelegateFileFilter.java?rev=591058&r1=591057&r2=591058&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/DelegateFileFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/DelegateFileFilter.java Thu Nov  1 08:47:05 2007
@@ -32,9 +32,9 @@
 public class DelegateFileFilter extends AbstractFileFilter implements Serializable {
 
     /** The Filename filter */
-    private FilenameFilter filenameFilter;
+    private final FilenameFilter filenameFilter;
     /** The File filter */
-    private FileFilter fileFilter;
+    private final FileFilter fileFilter;
 
     /**
      * Constructs a delegate file filter around an existing FilenameFilter.
@@ -46,6 +46,7 @@
             throw new IllegalArgumentException("The FilenameFilter must not be null");
         }
         this.filenameFilter = filter;
+        this.fileFilter = null;
     }
 
     /**
@@ -58,6 +59,7 @@
             throw new IllegalArgumentException("The FileFilter must not be null");
         }
         this.fileFilter = filter;
+        this.filenameFilter = null;
     }
 
     /**
@@ -96,7 +98,7 @@
      */
     public String toString() {
         String delegate = (fileFilter != null ? fileFilter.toString() : filenameFilter.toString()); 
-        return super.toString() + "(" + delegate.toString() + ")";
+        return super.toString() + "(" + delegate + ")";
     }
     
 }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NameFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NameFileFilter.java?rev=591058&r1=591057&r2=591058&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NameFileFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NameFileFilter.java Thu Nov  1 08:47:05 2007
@@ -47,9 +47,9 @@
 public class NameFileFilter extends AbstractFileFilter implements Serializable {
     
     /** The filenames to search for */
-    private String[] names;
+    private final String[] names;
     /** Whether the comparison is case sensitive. */
-    private IOCase caseSensitivity;
+    private final IOCase caseSensitivity;
 
     /**
      * Constructs a new case-sensitive name file filter for a single name.

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NotFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NotFileFilter.java?rev=591058&r1=591057&r2=591058&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NotFileFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NotFileFilter.java Thu Nov  1 08:47:05 2007
@@ -30,7 +30,7 @@
 public class NotFileFilter extends AbstractFileFilter implements Serializable {
     
     /** The filter */
-    private IOFileFilter filter;
+    private final IOFileFilter filter;
 
     /**
      * Constructs a new file filter that NOTs the result of another filters.

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java?rev=591058&r1=591057&r2=591058&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java Thu Nov  1 08:47:05 2007
@@ -46,10 +46,10 @@
 public class PrefixFileFilter extends AbstractFileFilter implements Serializable {
     
     /** The filename prefixes to search for */
-    private String[] prefixes;
+    private final String[] prefixes;
 
     /** Whether the comparison is case sensitive. */
-    private IOCase caseSensitivity = IOCase.SENSITIVE;
+    private final IOCase caseSensitivity;
 
     /**
      * Constructs a new Prefix file filter for a single prefix.
@@ -58,10 +58,7 @@
      * @throws IllegalArgumentException if the prefix is null
      */
     public PrefixFileFilter(String prefix) {
-        if (prefix == null) {
-            throw new IllegalArgumentException("The prefix must not be null");
-        }
-        this.prefixes = new String[] {prefix};
+        this(prefix, IOCase.SENSITIVE);
     }
 
     /**
@@ -74,7 +71,10 @@
      * @since Commons IO 1.4
      */
     public PrefixFileFilter(String prefix, IOCase caseSensitivity) {
-        this(prefix);
+        if (prefix == null) {
+            throw new IllegalArgumentException("The prefix must not be null");
+        }
+        this.prefixes = new String[] {prefix};
         this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
     }
 
@@ -88,10 +88,7 @@
      * @throws IllegalArgumentException if the prefix array is null
      */
     public PrefixFileFilter(String[] prefixes) {
-        if (prefixes == null) {
-            throw new IllegalArgumentException("The array of prefixes must not be null");
-        }
-        this.prefixes = prefixes;
+        this(prefixes, IOCase.SENSITIVE);
     }
 
     /**
@@ -107,7 +104,10 @@
      * @since Commons IO 1.4
      */
     public PrefixFileFilter(String[] prefixes, IOCase caseSensitivity) {
-        this(prefixes);
+        if (prefixes == null) {
+            throw new IllegalArgumentException("The array of prefixes must not be null");
+        }
+        this.prefixes = prefixes;
         this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
     }
 
@@ -119,10 +119,7 @@
      * @throws ClassCastException if the list does not contain Strings
      */
     public PrefixFileFilter(List prefixes) {
-        if (prefixes == null) {
-            throw new IllegalArgumentException("The list of prefixes must not be null");
-        }
-        this.prefixes = (String[]) prefixes.toArray(new String[prefixes.size()]);
+        this(prefixes, IOCase.SENSITIVE);
     }
 
     /**
@@ -136,7 +133,10 @@
      * @since Commons IO 1.4
      */
     public PrefixFileFilter(List prefixes, IOCase caseSensitivity) {
-        this(prefixes);
+        if (prefixes == null) {
+            throw new IllegalArgumentException("The list of prefixes must not be null");
+        }
+        this.prefixes = (String[]) prefixes.toArray(new String[prefixes.size()]);
         this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
     }
 

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/RegexFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/RegexFileFilter.java?rev=591058&r1=591057&r2=591058&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/RegexFileFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/RegexFileFilter.java Thu Nov  1 08:47:05 2007
@@ -45,7 +45,7 @@
 public class RegexFileFilter extends AbstractFileFilter implements Serializable {
 
     /** The regular expression pattern that will be used to match filenames */
-    private Pattern pattern;
+    private final Pattern pattern;
 
     /**
      * Construct a new regular expression filter.

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SizeFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SizeFileFilter.java?rev=591058&r1=591057&r2=591058&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SizeFileFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SizeFileFilter.java Thu Nov  1 08:47:05 2007
@@ -41,9 +41,9 @@
 public class SizeFileFilter extends AbstractFileFilter implements Serializable {
 
     /** The size threshold. */
-    private long size;
+    private final long size;
     /** Whether the files accepted will be larger or smaller. */
-    private boolean acceptLarger;
+    private final boolean acceptLarger;
 
     /**
      * Constructs a new size file filter for files equal to or 

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SuffixFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SuffixFileFilter.java?rev=591058&r1=591057&r2=591058&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SuffixFileFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SuffixFileFilter.java Thu Nov  1 08:47:05 2007
@@ -47,10 +47,10 @@
 public class SuffixFileFilter extends AbstractFileFilter implements Serializable {
     
     /** The filename suffixes to search for */
-    private String[] suffixes;
+    private final String[] suffixes;
 
     /** Whether the comparison is case sensitive. */
-    private IOCase caseSensitivity = IOCase.SENSITIVE;
+    private final IOCase caseSensitivity;
 
     /**
      * Constructs a new Suffix file filter for a single extension.
@@ -59,10 +59,7 @@
      * @throws IllegalArgumentException if the suffix is null
      */
     public SuffixFileFilter(String suffix) {
-        if (suffix == null) {
-            throw new IllegalArgumentException("The suffix must not be null");
-        }
-        this.suffixes = new String[] {suffix};
+        this(suffix, IOCase.SENSITIVE);
     }
 
     /**
@@ -75,7 +72,10 @@
      * @since Commons IO 1.4
      */
     public SuffixFileFilter(String suffix, IOCase caseSensitivity) {
-        this(suffix);
+        if (suffix == null) {
+            throw new IllegalArgumentException("The suffix must not be null");
+        }
+        this.suffixes = new String[] {suffix};
         this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
     }
 
@@ -89,10 +89,7 @@
      * @throws IllegalArgumentException if the suffix array is null
      */
     public SuffixFileFilter(String[] suffixes) {
-        if (suffixes == null) {
-            throw new IllegalArgumentException("The array of suffixes must not be null");
-        }
-        this.suffixes = suffixes;
+        this(suffixes, IOCase.SENSITIVE);
     }
 
     /**
@@ -108,7 +105,10 @@
      * @since Commons IO 1.4
      */
     public SuffixFileFilter(String[] suffixes, IOCase caseSensitivity) {
-        this(suffixes);
+        if (suffixes == null) {
+            throw new IllegalArgumentException("The array of suffixes must not be null");
+        }
+        this.suffixes = suffixes;
         this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
     }
 
@@ -120,10 +120,7 @@
      * @throws ClassCastException if the list does not contain Strings
      */
     public SuffixFileFilter(List suffixes) {
-        if (suffixes == null) {
-            throw new IllegalArgumentException("The list of suffixes must not be null");
-        }
-        this.suffixes = (String[]) suffixes.toArray(new String[suffixes.size()]);
+        this(suffixes, IOCase.SENSITIVE);
     }
 
     /**
@@ -137,7 +134,10 @@
      * @since Commons IO 1.4
      */
     public SuffixFileFilter(List suffixes, IOCase caseSensitivity) {
-        this(suffixes);
+        if (suffixes == null) {
+            throw new IllegalArgumentException("The list of suffixes must not be null");
+        }
+        this.suffixes = (String[]) suffixes.toArray(new String[suffixes.size()]);
         this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
     }
 

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java?rev=591058&r1=591057&r2=591058&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java Thu Nov  1 08:47:05 2007
@@ -52,9 +52,9 @@
 public class WildcardFileFilter extends AbstractFileFilter implements Serializable {
 
     /** The wildcards that will be used to match filenames. */
-    private String[] wildcards;
+    private final String[] wildcards;
     /** Whether the comparison is case sensitive. */
-    private IOCase caseSensitivity;
+    private final IOCase caseSensitivity;
 
     /**
      * Construct a new case-sensitive wildcard filter for a single wildcard.

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java?rev=591058&r1=591057&r2=591058&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java Thu Nov  1 08:47:05 2007
@@ -53,7 +53,7 @@
 public class WildcardFilter extends AbstractFileFilter implements Serializable {
 
     /** The wildcards that will be used to match filenames. */
-    private String[] wildcards;
+    private final String[] wildcards;
 
     /**
      * Construct a new case-sensitive wildcard filter for a single wildcard.