KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > io > findfile > FilterFindFile


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.io.findfile;
4
5 import java.io.File JavaDoc;
6 import java.io.FileFilter JavaDoc;
7 import java.util.List JavaDoc;
8 import java.util.ArrayList JavaDoc;
9
10 /**
11  * {@link FindFile} that uses file filters.
12  */

13 public class FilterFindFile extends FindFile {
14
15     public FilterFindFile() {
16     }
17
18     public FilterFindFile(String JavaDoc searchPath) {
19         super(searchPath);
20     }
21
22     public FilterFindFile(File JavaDoc searchPath) {
23         super(searchPath);
24     }
25
26     public FilterFindFile(String JavaDoc[] searchPath) {
27         super(searchPath);
28     }
29
30     // ---------------------------------------------------------------- filters
31

32     protected List JavaDoc ffilters = null;
33
34     /**
35      * Adds array of file filters.
36      */

37     public FindFile addFilters(FileFilter JavaDoc[] ff) {
38         if (ffilters == null) {
39             ffilters = new ArrayList JavaDoc();
40         }
41         for (int i = 0; i < ff.length; i++) {
42             ffilters.add(ff[i]);
43         }
44         return this;
45     }
46
47     /**
48      * Adds a file filter.
49      */

50     public FindFile addFilter(FileFilter JavaDoc ff) {
51         if (ffilters == null) {
52             ffilters = new ArrayList JavaDoc();
53         }
54         ffilters.add(ff);
55         return this;
56     }
57
58     /**
59      * Called on each file entry (file or directory) and returns <code>true</code>
60      * if file passes search criteria.
61      */

62     protected boolean onFileEntry(File JavaDoc currentFile) {
63         if (ffilters != null) {
64             for (int i = 0; i < ffilters.size(); i++) {
65                 FileFilter JavaDoc ff = (FileFilter JavaDoc) ffilters.get(i);
66                 if (ff.accept(currentFile) == false) {
67                     return false;
68                 }
69             }
70         }
71         return true;
72     }
73
74
75 }
76
Popular Tags