git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@290809 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -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 @@ import org.apache.tools.ant.types.ResourceCollection; | |||
| * @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; | |||
| @@ -183,4 +206,25 @@ public class Resources extends DataType implements ResourceCollection { | |||
| 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(); | |||
| } | |||
| } | |||
| @@ -22,6 +22,7 @@ import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.Collections; | |||
| import org.apache.tools.ant.types.Resource; | |||
| import org.apache.tools.ant.types.ResourceCollection; | |||
| /** | |||
| @@ -30,6 +31,29 @@ import org.apache.tools.ant.types.ResourceCollection; | |||
| */ | |||
| 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. | |||
| @@ -43,6 +67,18 @@ public class Union extends BaseResourceCollectionContainer { | |||
| 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()])); | |||
| } | |||
| /** | |||
| * Unify the contained Resources. | |||
| * @return a Collection of Resources. | |||