01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.util;
04:
05: import java.io.*;
06:
07: public class Wildcard implements FilenameFilter {
08: private String pattern;
09: private String prefix;
10: private String sufix;
11: private int length;
12:
13: public Wildcard(String pattern) {
14: int starIndex = pattern.indexOf("*");
15: if (starIndex > -1) {
16: prefix = pattern.substring(0, starIndex);
17: sufix = pattern.substring(starIndex + 1);
18: length = prefix.length() + sufix.length();
19: } else {
20: this .pattern = pattern;
21: }
22: }
23:
24: public boolean accept(File dir, String name) {
25: if (pattern != null)
26: return pattern.equals(name);
27:
28: boolean goodLength = name.length() >= length;
29: boolean goodPrefix = name.startsWith(prefix);
30: boolean goodSufix = name.endsWith(sufix);
31:
32: return goodLength && goodPrefix && goodSufix;
33: }
34: }
|