commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1022723 - in /commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor: FileAlterationObserver.java FileEntry.java
Date Thu, 14 Oct 2010 21:21:28 GMT
Author: niallp
Date: Thu Oct 14 21:21:27 2010
New Revision: 1022723

URL: http://svn.apache.org/viewvc?rev=1022723&view=rev
Log:
Move/reuse static empty arrays

Modified:
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileEntry.java

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java?rev=1022723&r1=1022722&r2=1022723&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java
Thu Oct 14 21:21:27 2010
@@ -24,6 +24,7 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOCase;
 import org.apache.commons.io.comparator.NameFileComparator;
 
@@ -120,9 +121,6 @@ import org.apache.commons.io.comparator.
  */
 public class FileAlterationObserver implements Serializable {
 
-    private static final File[] EMPTY_FILES = new File[0];
-    static final FileEntry[] EMPTY_ENTRIES = new FileEntry[0];
-
     private final List<FileAlterationListener> listeners = new CopyOnWriteArrayList<FileAlterationListener>();
     private final FileEntry rootEntry;
     private final FileFilter fileFilter;
@@ -292,7 +290,7 @@ public class FileAlterationObserver impl
     public void initialize() throws Exception {
         rootEntry.refresh(rootEntry.getFile());
         File[] files = listFiles(rootEntry.getFile());
-        FileEntry[] children = files.length > 0 ? new FileEntry[files.length] : EMPTY_ENTRIES;
+        FileEntry[] children = files.length > 0 ? new FileEntry[files.length] : FileEntry.EMPTY_ENTRIES;
         for (int i = 0; i < files.length; i++) {
             children[i] = createFileEntry(rootEntry, files[i]);
         }
@@ -322,7 +320,7 @@ public class FileAlterationObserver impl
         if (rootFile.exists()) {
             checkAndNotify(rootEntry, rootEntry.getChildren(), listFiles(rootFile));
         } else if (rootEntry.isExists()) {
-            checkAndNotify(rootEntry, rootEntry.getChildren(), EMPTY_FILES);
+            checkAndNotify(rootEntry, rootEntry.getChildren(), FileUtils.EMPTY_FILE_ARRAY);
         } else {
             // Didn't exist and still doesn't
         }
@@ -342,7 +340,7 @@ public class FileAlterationObserver impl
      */
     private void checkAndNotify(FileEntry parent, FileEntry[] previous, File[] files) {
         int c = 0;
-        FileEntry[] current = files.length > 0 ? new FileEntry[files.length] : EMPTY_ENTRIES;
+        FileEntry[] current = files.length > 0 ? new FileEntry[files.length] : FileEntry.EMPTY_ENTRIES;
         for (FileEntry entry : previous) {
             while (c < files.length && comparator.compare(entry.getFile(), files[c])
> 0) {
                 current[c] = createFileEntry(parent, files[c]);
@@ -355,7 +353,7 @@ public class FileAlterationObserver impl
                 current[c] = entry;
                 c++;
             } else {
-                checkAndNotify(entry, entry.getChildren(), EMPTY_FILES);
+                checkAndNotify(entry, entry.getChildren(), FileUtils.EMPTY_FILE_ARRAY);
                 doDelete(entry);
             }
         }
@@ -377,7 +375,7 @@ public class FileAlterationObserver impl
         FileEntry entry = parent.newChildInstance(file);
         entry.refresh(file);
         File[] files = listFiles(file);
-        FileEntry[] children = files.length > 0 ? new FileEntry[files.length] : EMPTY_ENTRIES;
+        FileEntry[] children = files.length > 0 ? new FileEntry[files.length] : FileEntry.EMPTY_ENTRIES;
         for (int i = 0; i < files.length; i++) {
             children[i] = createFileEntry(entry, files[i]);
         }
@@ -450,7 +448,7 @@ public class FileAlterationObserver impl
             children = (fileFilter == null) ? file.listFiles() : file.listFiles(fileFilter);
         }
         if (children == null) {
-            children = EMPTY_FILES;
+            children = FileUtils.EMPTY_FILE_ARRAY;
         }
         if (comparator != null && children.length > 1) {
             Arrays.sort(children, comparator);

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileEntry.java?rev=1022723&r1=1022722&r2=1022723&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileEntry.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileEntry.java Thu
Oct 14 21:21:27 2010
@@ -41,6 +41,8 @@ import java.io.Serializable;
  */
 public class FileEntry implements Serializable {
 
+    static final FileEntry[] EMPTY_ENTRIES = new FileEntry[0];
+
     private final FileEntry parent;
     private FileEntry[] children;
     private final File file;
@@ -149,7 +151,7 @@ public class FileEntry implements Serial
      * directory is empty
      */
     public FileEntry[] getChildren() {
-        return children != null ? children : FileAlterationObserver.EMPTY_ENTRIES;
+        return children != null ? children : EMPTY_ENTRIES;
     }
 
     /**



Mime
View raw message