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.Serializable; 21 import java.nio.file.FileVisitResult; 22 import java.nio.file.Path; 23 import java.nio.file.attribute.BasicFileAttributes; 24 25 /** 26 * A file filter that always returns true. 27 * <h2>Deprecating Serialization</h2> 28 * <p> 29 * <em>Serialization is deprecated and will be removed in 3.0.</em> 30 * </p> 31 * 32 * @since 1.0 33 * @see FileFilterUtils#trueFileFilter() 34 */ 35 public class TrueFileFilter implements IOFileFilter, Serializable { 36 37 private static final String TO_STRING = Boolean.TRUE.toString(); 38 39 private static final long serialVersionUID = 8782512160909720199L; 40 41 /** 42 * Singleton instance of true filter. 43 * 44 * @since 1.3 45 */ 46 public static final IOFileFilter TRUE = new TrueFileFilter(); 47 48 /** 49 * Singleton instance of true filter. Please use the identical TrueFileFilter.TRUE constant. The new name is more 50 * JDK 1.5 friendly as it doesn't clash with other values when using static imports. 51 */ 52 public static final IOFileFilter INSTANCE = TRUE; 53 54 /** 55 * Restrictive constructor. 56 */ 57 protected TrueFileFilter() { 58 } 59 60 /** 61 * Returns true. 62 * 63 * @param file the file to check (ignored) 64 * @return true 65 */ 66 @Override 67 public boolean accept(final File file) { 68 return true; 69 } 70 71 /** 72 * Returns true. 73 * 74 * @param dir the directory to check (ignored) 75 * @param name the file name (ignored) 76 * @return true 77 */ 78 @Override 79 public boolean accept(final File dir, final String name) { 80 return true; 81 } 82 83 /** 84 * Returns true. 85 * @param file the file to check (ignored) 86 * 87 * @return true 88 * @since 2.9.0 89 */ 90 @Override 91 public FileVisitResult accept(final Path file, final BasicFileAttributes attributes) { 92 return FileVisitResult.CONTINUE; 93 } 94 95 @Override 96 public IOFileFilter and(final IOFileFilter fileFilter) { 97 // TRUE AND expression <=> expression 98 return fileFilter; 99 } 100 101 @Override 102 public IOFileFilter negate() { 103 return FalseFileFilter.INSTANCE; 104 } 105 106 @Override 107 public IOFileFilter or(final IOFileFilter fileFilter) { 108 // TRUE OR expression <=> true 109 return INSTANCE; 110 } 111 112 @Override 113 public String toString() { 114 return TO_STRING; 115 } 116 }