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:
10: private String prefix;
11:
12: private String sufix;
13:
14: private int length;
15:
16: public Wildcard(String pattern) {
17: int starIndex = pattern.indexOf("*");
18: if (starIndex > -1) {
19: prefix = pattern.substring(0, starIndex);
20: sufix = pattern.substring(starIndex + 1);
21: length = prefix.length() + sufix.length();
22: } else {
23: this .pattern = pattern;
24: }
25: }
26:
27: public boolean accept(File dir, String name) {
28: if (pattern != null)
29: return pattern.equals(name);
30:
31: boolean goodLength = name.length() >= length;
32: boolean goodPrefix = name.startsWith(prefix);
33: boolean goodSufix = name.endsWith(sufix);
34:
35: return goodLength && goodPrefix && goodSufix;
36: }
37: }
|