1 18 package org.apache.tools.ant.types.resources; 19 20 import java.io.File ; 21 import java.util.Iterator ; 22 import java.util.NoSuchElementException ; 23 24 28 public class FileResourceIterator implements Iterator { 29 private File basedir; 30 private String [] files; 31 private int pos = 0; 32 33 36 public FileResourceIterator() { 37 } 38 39 44 public FileResourceIterator(File f) { 45 basedir = f; 46 } 47 48 54 public FileResourceIterator(File f, String [] s) { 55 this(f); 56 addFiles(s); 57 } 58 59 63 public void addFiles(String [] s) { 64 int start = (files == null) ? 0 : files.length; 65 String [] newfiles = new String [start + s.length]; 66 if (start > 0) { 67 System.arraycopy(files, 0, newfiles, 0, start); 68 } 69 files = newfiles; 70 System.arraycopy(s, 0, files, start, s.length); 71 } 72 73 77 public boolean hasNext() { 78 return pos < files.length; 79 } 80 81 85 public Object next() { 86 return nextResource(); 87 } 88 89 92 public void remove() { 93 throw new UnsupportedOperationException (); 94 } 95 96 100 public FileResource nextResource() { 101 if (!hasNext()) { 102 throw new NoSuchElementException (); 103 } 104 return new FileResource(basedir, files[pos++]); 105 } 106 107 } 108 | Popular Tags |