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 * https://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 *
86 * @param file the file to check (ignored).
87 * @param attributes the path's basic attributes (may be null).
88 * @return true.
89 * @since 2.9.0
90 */
91 @Override
92 public FileVisitResult accept(final Path file, final BasicFileAttributes attributes) {
93 return FileVisitResult.CONTINUE;
94 }
95
96 @Override
97 public IOFileFilter and(final IOFileFilter fileFilter) {
98 // TRUE AND expression <=> expression
99 return fileFilter;
100 }
101
102 @Override
103 public IOFileFilter negate() {
104 return FalseFileFilter.INSTANCE;
105 }
106
107 @Override
108 public IOFileFilter or(final IOFileFilter fileFilter) {
109 // TRUE OR expression <=> true
110 return INSTANCE;
111 }
112
113 @Override
114 public String toString() {
115 return TO_STRING;
116 }
117 }