001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.io.filefilter; 018 019 import java.io.File; 020 021 /** 022 * An abstract class which implements the Java FileFilter and FilenameFilter 023 * interfaces via the IOFileFilter interface. 024 * <p> 025 * Note that a subclass <b>must</b> override one of the accept methods, 026 * otherwise your class will infinitely loop. 027 * 028 * @since Commons IO 1.0 029 * @version $Revision: 736891 $ $Date: 2009-01-22 21:22:33 -0500 (Thu, 22 Jan 2009) $ 030 * 031 * @author Stephen Colebourne 032 */ 033 public abstract class AbstractFileFilter implements IOFileFilter { 034 035 /** 036 * Checks to see if the File should be accepted by this filter. 037 * 038 * @param file the File to check 039 * @return true if this file matches the test 040 */ 041 public boolean accept(File file) { 042 return accept(file.getParentFile(), file.getName()); 043 } 044 045 /** 046 * Checks to see if the File should be accepted by this filter. 047 * 048 * @param dir the directory File to check 049 * @param name the filename within the directory to check 050 * @return true if this file matches the test 051 */ 052 public boolean accept(File dir, String name) { 053 return accept(new File(dir, name)); 054 } 055 056 /** 057 * Provide a String representaion of this file filter. 058 * 059 * @return a String representaion 060 */ 061 @Override 062 public String toString() { 063 return getClass().getSimpleName(); 064 } 065 066 }