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 2010/01/10 00:50:24 UTC

svn commit: r897578 - in /commons/proper/io/trunk/src: java/org/apache/commons/io/DirectoryWalker.java test/org/apache/commons/io/DirectoryWalkerTestCase.java test/org/apache/commons/io/FileUtilsTestCase.java

Author: niallp
Date: Sat Jan  9 23:50:24 2010
New Revision: 897578

URL: http://svn.apache.org/viewvc?rev=897578&view=rev
Log:
Change DirectoryWalker to use generified Collection

Modified:
    commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java
    commons/proper/io/trunk/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java
    commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java?rev=897578&r1=897577&r2=897578&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java Sat Jan  9 23:50:24 2010
@@ -248,7 +248,7 @@
  * @since Commons IO 1.3
  * @version $Revision$
  */
-public abstract class DirectoryWalker {
+public abstract class DirectoryWalker<T> {
 
     /**
      * The file filter to use to filter files and directories.
@@ -326,7 +326,7 @@
      * @throws NullPointerException if the start directory is null
      * @throws IOException if an I/O Error occurs
      */
-    protected final void walk(File startDirectory, Collection<?> results) throws IOException {
+    protected final void walk(File startDirectory, Collection<T> results) throws IOException {
         if (startDirectory == null) {
             throw new NullPointerException("Start Directory is null");
         }
@@ -347,7 +347,7 @@
      * @param results  the collection of result objects, may be updated
      * @throws IOException if an I/O Error occurs
      */
-    private void walk(File directory, int depth, Collection<?> results) throws IOException {
+    private void walk(File directory, int depth, Collection<T> results) throws IOException {
         checkIfCancelled(directory, depth, results);
         if (handleDirectory(directory, depth, results)) {
             handleDirectoryStart(directory, depth, results);
@@ -390,7 +390,7 @@
      * @param results  the collection of result objects, may be updated
      * @throws IOException if an I/O Error occurs
      */
-    protected final void checkIfCancelled(File file, int depth, Collection<?> results) throws IOException {
+    protected final void checkIfCancelled(File file, int depth, Collection<T> results) throws IOException {
         if (handleIsCancelled(file, depth, results)) {
             throw new CancelException(file, depth);
         }
@@ -432,7 +432,7 @@
      * @throws IOException if an I/O Error occurs
      */
     protected boolean handleIsCancelled(
-            File file, int depth, Collection<?> results) throws IOException {
+            File file, int depth, Collection<T> results) throws IOException {
         // do nothing - overridable by subclass
         return false;  // not cancelled
     }
@@ -450,7 +450,7 @@
      * containing details at the point of cancellation. 
      * @throws IOException if an I/O Error occurs
      */
-    protected void handleCancelled(File startDirectory, Collection<?> results,
+    protected void handleCancelled(File startDirectory, Collection<T> results,
                        CancelException cancel) throws IOException {
         // re-throw exception - overridable by subclass
         throw cancel;
@@ -466,7 +466,7 @@
      * @param results  the collection of result objects, may be updated
      * @throws IOException if an I/O Error occurs
      */
-    protected void handleStart(File startDirectory, Collection<?> results) throws IOException {
+    protected void handleStart(File startDirectory, Collection<T> results) throws IOException {
         // do nothing - overridable by subclass
     }
 
@@ -485,7 +485,7 @@
      * @return true to process this directory, false to skip this directory
      * @throws IOException if an I/O Error occurs
      */
-    protected boolean handleDirectory(File directory, int depth, Collection<?> results) throws IOException {
+    protected boolean handleDirectory(File directory, int depth, Collection<T> results) throws IOException {
         // do nothing - overridable by subclass
         return true;  // process directory
     }
@@ -500,7 +500,7 @@
      * @param results  the collection of result objects, may be updated
      * @throws IOException if an I/O Error occurs
      */
-    protected void handleDirectoryStart(File directory, int depth, Collection<?> results) throws IOException {
+    protected void handleDirectoryStart(File directory, int depth, Collection<T> results) throws IOException {
         // do nothing - overridable by subclass
     }
 
@@ -529,7 +529,7 @@
      * @param results  the collection of result objects, may be updated
      * @throws IOException if an I/O Error occurs
      */
-    protected void handleFile(File file, int depth, Collection<?> results) throws IOException {
+    protected void handleFile(File file, int depth, Collection<T> results) throws IOException {
         // do nothing - overridable by subclass
     }
 
@@ -543,7 +543,7 @@
      * @param results  the collection of result objects, may be updated
      * @throws IOException if an I/O Error occurs
      */
-    protected void handleRestricted(File directory, int depth, Collection<?> results) throws IOException  {
+    protected void handleRestricted(File directory, int depth, Collection<T> results) throws IOException  {
         // do nothing - overridable by subclass
     }
 
@@ -557,7 +557,7 @@
      * @param results  the collection of result objects, may be updated
      * @throws IOException if an I/O Error occurs
      */
-    protected void handleDirectoryEnd(File directory, int depth, Collection<?> results) throws IOException {
+    protected void handleDirectoryEnd(File directory, int depth, Collection<T> results) throws IOException {
         // do nothing - overridable by subclass
     }
 
@@ -569,7 +569,7 @@
      * @param results  the collection of result objects, may be updated
      * @throws IOException if an I/O Error occurs
      */
-    protected void handleEnd(Collection<?> results) throws IOException {
+    protected void handleEnd(Collection<T> results) throws IOException {
         // do nothing - overridable by subclass
     }
 

Modified: commons/proper/io/trunk/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java?rev=897578&r1=897577&r2=897578&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java (original)
+++ commons/proper/io/trunk/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java Sat Jan  9 23:50:24 2010
@@ -371,7 +371,7 @@
      * Test DirectoryWalker implementation that finds files in a directory hierarchy
      * applying a file filter.
      */
-    private static class TestFileFinder extends DirectoryWalker {
+    private static class TestFileFinder extends DirectoryWalker<File> {
 
         protected TestFileFinder(FileFilter filter, int depthLimit) {
             super(filter, depthLimit);
@@ -394,13 +394,13 @@
 
         /** Handles a directory end by adding the File to the result set. */
         @Override
-        protected void handleDirectoryEnd(File directory, int depth, Collection results) {
+        protected void handleDirectoryEnd(File directory, int depth, Collection<File> results) {
             results.add(directory);
         }
 
         /** Handles a file by adding the File to the result set. */
         @Override
-        protected void handleFile(File file, int depth, Collection results) {
+        protected void handleFile(File file, int depth, Collection<File> results) {
             results.add(file);
         }
     }
@@ -419,7 +419,7 @@
 
         /** Always returns false. */
         @Override
-        protected boolean handleDirectory(File directory, int depth, Collection<?> results) {
+        protected boolean handleDirectory(File directory, int depth, Collection<File> results) {
             return false;
         }
     }
@@ -430,7 +430,7 @@
      * Test DirectoryWalker implementation that finds files in a directory hierarchy
      * applying a file filter.
      */
-    static class TestCancelWalker extends DirectoryWalker {
+    static class TestCancelWalker extends DirectoryWalker<File> {
         private String cancelFileName;
         private boolean suppressCancel;
 
@@ -449,7 +449,7 @@
 
         /** Handles a directory end by adding the File to the result set. */
         @Override
-        protected void handleDirectoryEnd(File directory, int depth, Collection results) throws IOException {
+        protected void handleDirectoryEnd(File directory, int depth, Collection<File> results) throws IOException {
             results.add(directory);
             if (cancelFileName.equals(directory.getName())) {
                 throw new CancelException(directory, depth);
@@ -458,7 +458,7 @@
 
         /** Handles a file by adding the File to the result set. */
         @Override
-        protected void handleFile(File file, int depth, Collection results) throws IOException {
+        protected void handleFile(File file, int depth, Collection<File> results) throws IOException {
             results.add(file);
             if (cancelFileName.equals(file.getName())) {
                 throw new CancelException(file, depth);
@@ -467,7 +467,7 @@
 
         /** Handles Cancel. */
         @Override
-        protected void handleCancelled(File startDirectory, Collection<?> results,
+        protected void handleCancelled(File startDirectory, Collection<File> results,
                        CancelException cancel) throws IOException {
             if (!suppressCancel) {
                 super.handleCancelled(startDirectory, results, cancel);
@@ -479,7 +479,7 @@
      * Test DirectoryWalker implementation that finds files in a directory hierarchy
      * applying a file filter.
      */
-    static class TestMultiThreadCancelWalker extends DirectoryWalker {
+    static class TestMultiThreadCancelWalker extends DirectoryWalker<File> {
         private String cancelFileName;
         private boolean suppressCancel;
         private boolean cancelled;
@@ -500,7 +500,7 @@
 
         /** Handles a directory end by adding the File to the result set. */
         @Override
-        protected void handleDirectoryEnd(File directory, int depth, Collection results) throws IOException {
+        protected void handleDirectoryEnd(File directory, int depth, Collection<File> results) throws IOException {
             results.add(directory);
             assertEquals(false, cancelled);
             if (cancelFileName.equals(directory.getName())) {
@@ -510,7 +510,7 @@
 
         /** Handles a file by adding the File to the result set. */
         @Override
-        protected void handleFile(File file, int depth, Collection results) throws IOException {
+        protected void handleFile(File file, int depth, Collection<File> results) throws IOException {
             results.add(file);
             assertEquals(false, cancelled);
             if (cancelFileName.equals(file.getName())) {
@@ -520,13 +520,13 @@
 
         /** Handles Cancelled. */
         @Override
-        protected boolean handleIsCancelled(File file, int depth, Collection<?> results) throws IOException {
+        protected boolean handleIsCancelled(File file, int depth, Collection<File> results) throws IOException {
             return cancelled;
         }
 
         /** Handles Cancel. */
         @Override
-        protected void handleCancelled(File startDirectory, Collection<?> results,
+        protected void handleCancelled(File startDirectory, Collection<File> results,
                        CancelException cancel) throws IOException {
             if (!suppressCancel) {
                 super.handleCancelled(startDirectory, results, cancel);

Modified: commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java?rev=897578&r1=897577&r2=897578&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java (original)
+++ commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java Sat Jan  9 23:50:24 2010
@@ -1667,7 +1667,7 @@
     /**
      * DirectoryWalker implementation that recursively lists all files and directories.
      */
-    static class ListDirectoryWalker extends DirectoryWalker {
+    static class ListDirectoryWalker extends DirectoryWalker<File> {
         ListDirectoryWalker() {
             super();
         }
@@ -1678,7 +1678,7 @@
         }
 
         @Override
-        protected void handleDirectoryStart(File directory, int depth, Collection results) throws IOException {
+        protected void handleDirectoryStart(File directory, int depth, Collection<File> results) throws IOException {
             // Add all directories except the starting directory
             if (depth > 0) {
                 results.add(directory);
@@ -1686,7 +1686,7 @@
         }
 
         @Override
-        protected void handleFile(File file, int depth, Collection results) throws IOException {
+        protected void handleFile(File file, int depth, Collection<File> results) throws IOException {
             results.add(file);
         }
     }