View Javadoc
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 false.
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#falseFileFilter()
34   */
35  public class FalseFileFilter implements IOFileFilter, Serializable {
36  
37      private static final String TO_STRING = Boolean.FALSE.toString();
38  
39      /**
40       * Singleton instance of false filter.
41       *
42       * @since 1.3
43       */
44      public static final IOFileFilter FALSE = new FalseFileFilter();
45  
46      /**
47       * Singleton instance of false filter. Please use the identical FalseFileFilter.FALSE constant. The new name is more
48       * JDK 1.5 friendly as it doesn't clash with other values when using static imports.
49       */
50      public static final IOFileFilter INSTANCE = FALSE;
51  
52      private static final long serialVersionUID = 6210271677940926200L;
53  
54      /**
55       * Restrictive constructor.
56       */
57      protected FalseFileFilter() {
58      }
59  
60      /**
61       * Returns false.
62       *
63       * @param file the file to check (ignored)
64       * @return false
65       */
66      @Override
67      public boolean accept(final File file) {
68          return false;
69      }
70  
71      /**
72       * Returns false.
73       *
74       * @param dir the directory to check (ignored)
75       * @param name the file name (ignored)
76       * @return false
77       */
78      @Override
79      public boolean accept(final File dir, final String name) {
80          return false;
81      }
82  
83      /**
84       * Returns false.
85       *
86       * @param file the file to check (ignored)
87       *
88       * @return false
89       * @since 2.9.0
90       */
91      @Override
92      public FileVisitResult accept(final Path file, final BasicFileAttributes attributes) {
93          return FileVisitResult.TERMINATE;
94      }
95  
96      @Override
97      public IOFileFilter and(final IOFileFilter fileFilter) {
98          // FALSE AND expression <=> FALSE
99          return INSTANCE;
100     }
101 
102     @Override
103     public IOFileFilter negate() {
104         return TrueFileFilter.INSTANCE;
105     }
106 
107     @Override
108     public IOFileFilter or(final IOFileFilter fileFilter) {
109         // FALSE OR expression <=> expression
110         return fileFilter;
111     }
112 
113     @Override
114     public String toString() {
115         return TO_STRING;
116     }
117 }