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 */
017package org.apache.commons.io.filefilter;
018
019import 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 1.0
029 * @version $Id: AbstractFileFilter.java 1415850 2012-11-30 20:51:39Z ggregory $
030 */
031public abstract class AbstractFileFilter implements IOFileFilter {
032
033    /**
034     * Checks to see if the File should be accepted by this filter.
035     * 
036     * @param file  the File to check
037     * @return true if this file matches the test
038     */
039    public boolean accept(final File file) {
040        return accept(file.getParentFile(), file.getName());
041    }
042
043    /**
044     * Checks to see if the File should be accepted by this filter.
045     * 
046     * @param dir  the directory File to check
047     * @param name  the filename within the directory to check
048     * @return true if this file matches the test
049     */
050    public boolean accept(final File dir, final String name) {
051        return accept(new File(dir, name));
052    }
053
054    /**
055     * Provide a String representaion of this file filter.
056     *
057     * @return a String representaion
058     */
059    @Override
060    public String toString() {
061        return getClass().getSimpleName();
062    }
063
064}