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 *
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    @Override
040    public boolean accept(final File file) {
041        return accept(file.getParentFile(), file.getName());
042    }
043
044    /**
045     * Checks to see if the File should be accepted by this filter.
046     *
047     * @param dir  the directory File to check
048     * @param name  the file name within the directory to check
049     * @return true if this file matches the test
050     */
051    @Override
052    public boolean accept(final File dir, final String name) {
053        return accept(new File(dir, name));
054    }
055
056    /**
057     * Provide a String representation of this file filter.
058     *
059     * @return a String representation
060     */
061    @Override
062    public String toString() {
063        return getClass().getSimpleName();
064    }
065
066}