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 import java.io.FileFilter; 21 import java.io.FilenameFilter; 22 import java.nio.file.FileVisitResult; 23 import java.nio.file.Path; 24 import java.nio.file.attribute.BasicFileAttributes; 25 26 import org.apache.commons.io.file.PathFilter; 27 28 /** 29 * An interface which brings the FileFilter, FilenameFilter, and PathFilter interfaces together. 30 * 31 * @since 1.0 32 */ 33 public interface IOFileFilter extends FileFilter, FilenameFilter, PathFilter { 34 35 /** 36 * An empty String array. 37 */ 38 String[] EMPTY_STRING_ARRAY = {}; 39 40 /** 41 * Checks to see if the File should be accepted by this filter. 42 * <p> 43 * Defined in {@link java.io.FileFilter}. 44 * </p> 45 * 46 * @param file the File to check. 47 * @return true if this file matches the test. 48 */ 49 @Override accept(File file)50 boolean accept(File file); 51 52 /** 53 * Checks to see if the File should be accepted by this filter. 54 * <p> 55 * Defined in {@link java.io.FilenameFilter}. 56 * </p> 57 * 58 * @param dir the directory File to check. 59 * @param name the file name within the directory to check. 60 * @return true if this file matches the test. 61 */ 62 @Override accept(File dir, String name)63 boolean accept(File dir, String name); 64 65 /** 66 * Checks to see if the Path should be accepted by this filter. 67 * 68 * @param path the Path to check. 69 * @return true if this path matches the test. 70 * @since 2.9.0 71 */ 72 @Override accept(final Path path, final BasicFileAttributes attributes)73 default FileVisitResult accept(final Path path, final BasicFileAttributes attributes) { 74 return AbstractFileFilter.toDefaultFileVisitResult(accept(path.toFile())); 75 } 76 77 /** 78 * Creates a new "and" filter with this filter. 79 * 80 * @param fileFilter the filter to "and". 81 * @return a new filter. 82 * @since 2.9.0 83 */ and(final IOFileFilter fileFilter)84 default IOFileFilter and(final IOFileFilter fileFilter) { 85 return new AndFileFilter(this, fileFilter); 86 } 87 88 /** 89 * Creates a new "not" filter with this filter. 90 * 91 * @return a new filter. 92 * @since 2.9.0 93 */ negate()94 default IOFileFilter negate() { 95 return new NotFileFilter(this); 96 } 97 98 /** 99 * 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 */ or(final IOFileFilter fileFilter)105 default IOFileFilter or(final IOFileFilter fileFilter) { 106 return new OrFileFilter(this, fileFilter); 107 } 108 109 } 110