    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;
    020import java.io.FileFilter;
    021import java.io.FilenameFilter;
    022import java.nio.file.FileVisitResult;
    023import java.nio.file.Path;
    024import java.nio.file.attribute.BasicFileAttributes;
    025
    026import org.apache.commons.io.file.PathFilter;
    027
    028/**
    029 * An interface which brings the FileFilter, FilenameFilter, and PathFilter interfaces together.
    030 *
    031 * @since 1.0
    032 */
    033public interface IOFileFilter extends FileFilter, FilenameFilter, PathFilter {
    034
    035    /**
    036     * An empty String array.
    037     */
    038    String[] EMPTY_STRING_ARRAY = {};
    039
    040    /**
    041     * Checks to see if the File should be accepted by this filter.
    042     * <p>
    043     * Defined in {@link java.io.FileFilter}.
    044     * </p>
    045     *
    046     * @param file the File to check.
    047     * @return true if this file matches the test.
    048     */
    049    @Override
    050    boolean accept(File file);
    051
    052    /**
    053     * Checks to see if the File should be accepted by this filter.
    054     * <p>
    055     * Defined in {@link java.io.FilenameFilter}.
    056     * </p>
    057     *
    058     * @param dir the directory File to check.
    059     * @param name the file name within the directory to check.
    060     * @return true if this file matches the test.
    061     */
    062    @Override
    063    boolean accept(File dir, String name);
    064
    065    /**
    066     * Checks to see if the Path should be accepted by this filter.
    067     *
    068     * @param path the Path to check.
    069     * @return true if this path matches the test.
    070     * @since 2.9.0
    071     */
    072    @Override
    073    default FileVisitResult accept(final Path path, final BasicFileAttributes attributes) {
    074        return AbstractFileFilter.toFileVisitResult(accept(path.toFile()), path);
    075    }
    076
    077    /**
    078     * Creates a new "and" filter with this filter.
    079     *
    080     * @param fileFilter the filter to "and".
    081     * @return a new filter.
    082     * @since 2.9.0
    083     */
    084    default IOFileFilter and(final IOFileFilter fileFilter) {
    085        return new AndFileFilter(this, fileFilter);
    086    }
    087
    088    /**
    089     * Creates a new "not" filter with this filter.
    090     *
    091     * @return a new filter.
    092     * @since 2.9.0
    093     */
    094    default IOFileFilter negate() {
    095        return new NotFileFilter(this);
    096    }
    097
    098    /**
    099     * Creates a new "or" filter with this filter.
    100     *
    101     * @param fileFilter the filter to "or".
    102     * @return a new filter.
    103     * @since 2.9.0
    104     */
    105    default IOFileFilter or(final IOFileFilter fileFilter) {
    106        return new OrFileFilter(this, fileFilter);
    107    }
    108
    109}