1 18 package org.apache.tools.ant.types.resources; 19 20 import java.util.Iterator ; 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 24 import org.apache.tools.ant.BuildException; 25 26 31 public class First extends BaseResourceCollectionWrapper { 32 private static final String BAD_COUNT 33 = "count of first resources should be set to an int >= 0"; 34 35 private int count = 1; 36 37 41 public synchronized void setCount(int i) { 42 count = i; 43 } 44 45 49 public synchronized int getCount() { 50 return count; 51 } 52 53 57 protected Collection getCollection() { 58 int ct = getCount(); 59 if (ct < 0) { 60 throw new BuildException(BAD_COUNT); 61 } 62 Iterator iter = getResourceCollection().iterator(); 63 ArrayList al = new ArrayList (ct); 64 for (int i = 0; i < ct && iter.hasNext(); i++) { 65 al.add(iter.next()); 66 } 67 return al; 68 } 69 70 } 71 | Popular Tags |