01: /*
02: * This file or a portion of this file is licensed under the terms of
03: * the Globus Toolkit Public License, found in file GTPL, or at
04: * http://www.globus.org/toolkit/download/license.html. This notice must
05: * appear in redistributions of this file, with or without modification.
06: *
07: * Redistributions of this Software, with or without modification, must
08: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
09: * some other similar material which is provided with the Software (if
10: * any).
11: *
12: * Copyright 1999-2004 University of Chicago and The University of
13: * Southern California. All rights reserved.
14: */
15: package org.griphyn.vdl.diagnozer;
16:
17: import java.io.*;
18: import java.util.regex.*;
19:
20: /**
21: * Implements a file filter that search by regular expression matches.
22: */
23: class FindTheRegex implements FilenameFilter {
24: /**
25: * Compiled pattern container.
26: */
27: private Pattern m_pattern;
28:
29: /**
30: * C'tor
31: * @param re is the regular expression to filter with
32: */
33: public FindTheRegex(String re) {
34: m_pattern = Pattern.compile(re);
35: }
36:
37: /**
38: * Tests if a specified file should be included in a file list.
39: *
40: * @param dir the directory in which the file was found.
41: * @param name the name of the file.
42: * @return <code>true</code> iff the name should be included in the
43: * file list; <code>false</code> otherwise.
44: */
45: public boolean accept(File dir, String name) {
46: Matcher m = m_pattern.matcher(name);
47: return m.matches();
48: }
49: }
|