ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r290809 - in /ant/core/trunk/src/main/org/apache/tools/ant/types/resources: Resources.java Union.java
Date Wed, 21 Sep 2005 19:50:52 GMT
Author: mbenson
Date: Wed Sep 21 12:50:49 2005
New Revision: 290809

URL: http://svn.apache.org/viewcvs?rev=290809&view=rev
Log:
convenience additions + Resources.toString()

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

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Resources.java?rev=290809&r1=290808&r2=290809&view=diff
==============================================================================
--- 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 Wed Sep 21
12:50:49 2005
@@ -17,6 +17,7 @@
 
 package org.apache.tools.ant.types.resources;
 
+import java.io.File;
 import java.util.Stack;
 import java.util.Vector;
 import java.util.Iterator;
@@ -35,6 +36,28 @@
  * @since Ant 1.7
  */
 public class Resources extends DataType implements ResourceCollection {
+    /** static empty ResourceCollection */
+    public static final ResourceCollection NONE = new ResourceCollection() {
+        public boolean isFilesystemOnly() {
+            return true;
+        }
+        public Iterator iterator() {
+            return new Iterator() {
+                public Object next() {
+                    throw new NoSuchElementException();
+                }
+                public boolean hasNext() {
+                    return false;
+                }
+                public void remove() {
+                    throw new UnsupportedOperationException();
+                }
+            };
+        }
+        public int size() {
+            return 0;
+        }
+    };
 
     private class MyCollection extends AbstractCollection {
         int size;
@@ -181,6 +204,27 @@
             throw new BuildException("Resources:  no resources specified.");
         }
         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.size() == 0) {
+            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();
     }
 
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java?rev=290809&r1=290808&r2=290809&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java Wed Sep 21 12:50:49
2005
@@ -22,6 +22,7 @@
 import java.util.Collection;
 import java.util.Collections;
 
+import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
 
 /**
@@ -31,6 +32,29 @@
 public class Union extends BaseResourceCollectionContainer {
 
     /**
+     * Static convenience method to union an arbitrary set of Resources.
+     * @param rc a ResourceCollection.
+     * @return a Union.
+     */
+    public static Union getInstance(ResourceCollection rc) {
+        return rc instanceof Union ? (Union) rc : new Union(rc);
+    }
+
+    /**
+     * Default constructor.
+     */
+    public Union() {
+    }
+
+    /**
+     * Convenience constructor.
+     * @param rc the ResourceCollection to add.
+     */
+    public Union(ResourceCollection rc) {
+        add(rc);
+    }
+
+    /**
      * Returns all Resources in String format. Moved up from
      * Path for convenience.
      * @return String array of Resources.
@@ -41,6 +65,18 @@
         }
         Collection result = getCollection(true);
         return (String[]) (result.toArray(new String[result.size()]));
+    }
+
+    /**
+     * Convenience method.
+     * @return Resource[]
+     */
+    public Resource[] listResources() {
+        if (isReference()) {
+            return ((Union) getCheckedRef()).listResources();
+        }
+        Collection result = getCollection();
+        return (Resource[]) (result.toArray(new Resource[result.size()]));
     }
 
     /**



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


Mime
View raw message