You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by mb...@apache.org on 2006/11/21 20:21:56 UTC

svn commit: r477837 - /ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java

Author: mbenson
Date: Tue Nov 21 11:21:56 2006
New Revision: 477837

URL: http://svn.apache.org/viewvc?view=rev&rev=477837
Log:
move a public method above private and protected; lazily create the child-holding Vector.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java?view=diff&rev=477837&r1=477836&r2=477837
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java Tue Nov 21 11:21:56 2006
@@ -19,10 +19,12 @@
 package org.apache.tools.ant.types.resources;
 
 import java.io.File;
+import java.util.List;
 import java.util.Stack;
 import java.util.Vector;
 import java.util.Iterator;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.AbstractCollection;
 import java.util.NoSuchElementException;
 
@@ -65,7 +67,7 @@
 
         MyCollection() {
             size = 0;
-            for (Iterator rci = rc.iterator(); rci.hasNext();) {
+            for (Iterator rci = getNested().iterator(); rci.hasNext();) {
                 size += ((ResourceCollection) rci.next()).size();
             }
         }
@@ -76,7 +78,7 @@
             return new MyIterator();
         }
         private class MyIterator implements Iterator {
-            private Iterator rci = rc.iterator();
+            private Iterator rci = getNested().iterator();
             private Iterator ri = null;
 
             public boolean hasNext() {
@@ -99,8 +101,8 @@
         }
     }
 
-    private Vector rc = new Vector();
-    private Collection coll = null;
+    private Vector rc;
+    private Collection coll;
 
     /**
      * Add a ResourceCollection.
@@ -113,6 +115,9 @@
         if (c == null) {
             return;
         }
+        if (rc == null) {
+            rc = new Vector();
+        }
         rc.add(c);
         FailFast.invalidate(this);
         coll = null;
@@ -153,7 +158,7 @@
         }
         validate();
 
-        for (Iterator i = rc.iterator(); i.hasNext();) {
+        for (Iterator i = getNested().iterator(); i.hasNext();) {
             if ((!((ResourceCollection) i.next()).isFilesystemOnly())) {
                 return false;
             }
@@ -162,6 +167,27 @@
     }
 
     /**
+     * Format this BaseResourceCollectionContainer as a String.
+     * @return a descriptive <code>String</code>.
+     */
+    public synchronized String toString() {
+        if (isReference()) {
+            return getCheckedRef().toString();
+        }
+        if (coll == null || coll.isEmpty()) {
+            return "";
+        }
+        StringBuffer sb = new StringBuffer();
+        for (Iterator i = coll.iterator(); i.hasNext();) {
+            if (sb.length() > 0) {
+                sb.append(File.pathSeparatorChar);
+            }
+            sb.append(i.next());
+        }
+        return sb.toString();
+    }
+
+    /**
      * Overrides the version of DataType to recurse on all DataType
      * child elements that may have been added.
      * @param stk the stack of data types to use (recursively).
@@ -176,7 +202,7 @@
         if (isReference()) {
             super.dieOnCircularReference(stk, p);
         } else {
-            for (Iterator i = rc.iterator(); i.hasNext();) {
+            for (Iterator i = getNested().iterator(); i.hasNext();) {
                 Object o = i.next();
                 if (o instanceof DataType) {
                     invokeCircularReferenceCheck((DataType) o, stk, p);
@@ -200,25 +226,7 @@
         coll = (coll == null) ? new MyCollection() : coll;
     }
 
-    /**
-     * Format this BaseResourceCollectionContainer as a String.
-     * @return a descriptive <code>String</code>.
-     */
-    public synchronized String toString() {
-        if (isReference()) {
-            return getCheckedRef().toString();
-        }
-        if (coll == null || coll.isEmpty()) {
-            return "";
-        }
-        StringBuffer sb = new StringBuffer();
-        for (Iterator i = coll.iterator(); i.hasNext();) {
-            if (sb.length() > 0) {
-                sb.append(File.pathSeparatorChar);
-            }
-            sb.append(i.next());
-        }
-        return sb.toString();
+    private synchronized List getNested() {
+        return rc == null ? Collections.EMPTY_LIST : rc;
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org