KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > file > filters > WildcardFileFilter


1 package jodd.file.filters;
2
3 import java.io.File;
4 import java.io.FileFilter;
5 import java.util.regex.Matcher;
6 import java.util.regex.Pattern;
7
8 import jodd.util.StringFlags;
9 import jodd.util.StringUtil;
10
11 /**
12  * FileFilter that matches files against wildcard pattern (* and ?).
13  *
14  * For more details check the <code>FileFilterAbs</code> documentation.
15  * For wildcard matching check the <code>StringUtil</code> documentation.
16  *
17  * @see jodd.file.filters.FileFilterAbs
18  * @see jodd.util.StringUtil
19  */

20 public class WildcardFileFilter extends FileFilterAbs {
21
22     // ---------------------------------------------------------------- construction
23

24     /**
25      * Regular Expression file filter.
26      *
27      * @param pattern regexp pattern
28      * @param opt option string
29      */

30     public WildcardFileFilter(String pattern, String opt) {
31         super(pattern, opt);
32     }
33
34     /**
35      * Regular Expression file filter with default behaviour.
36      *
37      * @param pattern pattern
38      */

39     public WildcardFileFilter(String pattern) {
40         super(pattern);
41     }
42
43     /**
44      * Regular Expression file filter with no behaviour and that may be
45      * configured later.
46      */

47     public WildcardFileFilter() {
48         super();
49     }
50
51     // ---------------------------------------------------------------- FileFilterAbs.match()
52

53     /**
54      * Wildcard matching.
55      *
56      * @param file File to match.
57      *
58      * @return <code>true</code> if file name matches regular expression pattern,
59      * <code>false</code> otherwise.
60      */

61     public boolean match(File file) {
62         return StringUtil.match(getFileName(file), pattern);
63     }
64 }
65
66
Popular Tags