}\r
}\r
}\r
+\r
+ public static final void toDoAll(Set<String> set, ForDoAll fda) throws Exception {\r
+ Iterator<String> di = set.iterator();\r
+ while (di.hasNext()) {\r
+ fda.run(di.next());\r
+ }\r
+ }\r
\r
- public static void toDoAll(String path, ForDoAll fda, int type) throws Exception { // filter of file type can be done in toDo\r
+ public static final void toDoAll(String path, ForDoAll fda, int type) throws Exception { // filter of file type can be done in toDo\r
String[] list = new File(path).list();\r
File test;\r
\r
if (type == DIR || type == BOTH) {\r
- fda.toDo(path);\r
+ if (fda.dirFilter(path)) {\r
+ fda.run(path);\r
+ }\r
}\r
for (int i = 0 ; i < list.length ; i++) {\r
test = new File(path + File.separator + list[i]);\r
toDoAll(path + File.separator + list[i], fda, type);\r
} else {\r
if (type == FILE || type == BOTH) {\r
- fda.toDo(path + File.separator + list[i]);\r
+ if (fda.fileFilter(path + File.separator + list[i])) {\r
+ fda.run(path + File.separator + list[i]);\r
+ }\r
}\r
}\r
}\r
}\r
\r
public static interface ForDoAll {\r
- public void toDo(String filepath) throws Exception;\r
- }\r
- /*\r
- // this PathIterator is based on HashSet, an thread implementation is required.\r
- private final class PathIterator implements ForDoAll{\r
- PathIterator(String path) throws Exception {\r
- startpath = path;\r
- Common.toDoAll(startpath, this, mode);\r
- }\r
- PathIterator(String path, int md) throws Exception {\r
- startpath = path;\r
- mode = md;\r
- Common.toDoAll(startpath, this, mode);\r
- }\r
- private String startpath;\r
- private int mode = Common.BOTH;\r
- private HashSet<String> pathlist = new HashSet<String>();\r
- private Iterator<String> it = pathlist.iterator();\r
+ public void run(String filepath) throws Exception;\r
\r
- public final void toDo(String path) throws Exception {\r
- pathlist.add(path);\r
- }\r
+ public boolean dirFilter(String filepath);\r
\r
- public final String next() {\r
- return it.next();\r
- }\r
- \r
- public final boolean hasNext() {\r
- return it.hasNext();\r
- }\r
- \r
- public final String toString() {\r
- return pathlist.toString();\r
- }\r
- }\r
- \r
- public final PathIterator getPathIterator(String path, int md) throws Exception {\r
- return new PathIterator(path, md);\r
+ public boolean fileFilter(String filepath);\r
}\r
- */\r
}\r