• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package org.apache.commons.io.filefilter;
18 
19 import java.io.File;
20 
21 /**
22  * An abstract class which implements the Java FileFilter and FilenameFilter
23  * interfaces via the IOFileFilter interface.
24  * <p>
25  * Note that a subclass <b>must</b> override one of the accept methods,
26  * otherwise your class will infinitely loop.
27  *
28  * @since Commons IO 1.0
29  * @version $Revision: 539231 $ $Date: 2007-05-18 04:10:33 +0100 (Fri, 18 May 2007) $
30  *
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      */
accept(File file)41     public boolean accept(File 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      */
accept(File dir, String name)52     public boolean accept(File dir, String name) {
53         return accept(new File(dir, name));
54     }
55 
56     /**
57      * Provide a String representaion of this file filter.
58      *
59      * @return a String representaion
60      */
toString()61     public String toString() {
62         String name = getClass().getName();
63         int period = name.lastIndexOf('.');
64         return (period > 0 ? name.substring(period + 1) : name);
65     }
66 
67 }
68