KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > io > filefilter > AbstractFileFilter


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.io.filefilter;
17
18 import java.io.File JavaDoc;
19
20 /**
21  * An abstract class which implements the Java FileFilter and FilenameFilter
22  * interfaces via the IOFileFilter interface.
23  * <p>
24  * Note that a subclass <b>must</b> override one of the accept methods,
25  * otherwise your class will infinitely loop.
26  *
27  * @since Commons IO 1.0
28  * @version $Revision: 1.9 $ $Date: 2004/02/23 04:37:57 $
29  *
30  * @author Henri Yandell
31  * @author Stephen Colebourne
32  */

33 public abstract class AbstractFileFilter implements IOFileFilter {
34
35     /**
36      * Checks to see if the File should be accepted by this filter.
37      *
38      * @param file the File to check
39      * @return true if this file matches the test
40      */

41     public boolean accept(File JavaDoc file) {
42         return accept(file.getParentFile(), file.getName());
43     }
44
45     /**
46      * Checks to see if the File should be accepted by this filter.
47      *
48      * @param dir the directory File to check
49      * @param name the filename within the directory to check
50      * @return true if this file matches the test
51      */

52     public boolean accept(File JavaDoc dir, String JavaDoc name) {
53         String JavaDoc filename = dir.getName() + File.separator + name;
54         return accept(new File JavaDoc(filename));
55     }
56
57 }
58
Popular Tags