1 18 package org.apache.tools.ant.types.resources; 19 20 import java.util.List ; 21 import java.util.Iterator ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.types.ResourceCollection; 27 28 33 public class Intersect extends BaseResourceCollectionContainer { 34 35 39 protected Collection getCollection() { 40 List rcs = getResourceCollections(); 41 int size = rcs.size(); 42 if (size < 2) { 43 throw new BuildException("The intersection of " + size 44 + " resource collection" + ((size == 1) ? "" : "s") 45 + " is undefined."); 46 } 47 ArrayList al = new ArrayList (); 48 Iterator rc = rcs.iterator(); 49 al.addAll(collect(rc.next())); 50 while (rc.hasNext()) { 51 al.retainAll(collect(rc.next())); 52 } 53 return al; 54 } 55 56 private ArrayList collect(Object o) { 57 ArrayList result = new ArrayList (); 58 for (Iterator i = ((ResourceCollection) o).iterator(); i.hasNext();) { 59 result.add(i.next()); 60 } 61 return result; 62 } 63 } 64 | Popular Tags |