KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > io > filter > RegExpFileFilter


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

3 package jodd.io.filter;
4
5 import java.io.File JavaDoc;
6 import java.util.regex.Matcher JavaDoc;
7 import java.util.regex.Pattern JavaDoc;
8
9 /**
10  * FileFilter that matches files with use of Regular Expression.
11  *
12  * Some tips for regular expressions:
13  * <ul>
14  * <li>.* : matches any number of character</li>
15  * <li>.? : matches zero or one character</li>
16  * </ul>
17  */

18 public class RegExpFileFilter extends FileFilterBase {
19
20     private Pattern JavaDoc regexpPattern = null;
21
22     public RegExpFileFilter(String JavaDoc pattern) {
23         regexpPattern = Pattern.compile(pattern);
24     }
25
26     public boolean accept(File JavaDoc dir, String JavaDoc name) {
27         return regexpPattern.matcher(name).matches();
28     }
29 }
30
31
Popular Tags