FalseFileFilter.java

  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. import java.io.File;
  19. import java.io.Serializable;
  20. import java.nio.file.FileVisitResult;
  21. import java.nio.file.Path;
  22. import java.nio.file.attribute.BasicFileAttributes;

  23. /**
  24.  * A file filter that always returns false.
  25.  * <h2>Deprecating Serialization</h2>
  26.  * <p>
  27.  * <em>Serialization is deprecated and will be removed in 3.0.</em>
  28.  * </p>
  29.  *
  30.  * @since 1.0
  31.  * @see FileFilterUtils#falseFileFilter()
  32.  */
  33. public class FalseFileFilter implements IOFileFilter, Serializable {

  34.     private static final String TO_STRING = Boolean.FALSE.toString();

  35.     /**
  36.      * Singleton instance of false filter.
  37.      *
  38.      * @since 1.3
  39.      */
  40.     public static final IOFileFilter FALSE = new FalseFileFilter();

  41.     /**
  42.      * Singleton instance of false filter. Please use the identical FalseFileFilter.FALSE constant. The new name is more
  43.      * JDK 1.5 friendly as it doesn't clash with other values when using static imports.
  44.      */
  45.     public static final IOFileFilter INSTANCE = FALSE;

  46.     private static final long serialVersionUID = 6210271677940926200L;

  47.     /**
  48.      * Restrictive constructor.
  49.      */
  50.     protected FalseFileFilter() {
  51.     }

  52.     /**
  53.      * Returns false.
  54.      *
  55.      * @param file the file to check (ignored)
  56.      * @return false
  57.      */
  58.     @Override
  59.     public boolean accept(final File file) {
  60.         return false;
  61.     }

  62.     /**
  63.      * Returns false.
  64.      *
  65.      * @param dir the directory to check (ignored)
  66.      * @param name the file name (ignored)
  67.      * @return false
  68.      */
  69.     @Override
  70.     public boolean accept(final File dir, final String name) {
  71.         return false;
  72.     }

  73.     /**
  74.      * Returns false.
  75.      *
  76.      * @param file the file to check (ignored)
  77.      * @param attributes the path's basic attributes (may be null).
  78.      * @return false
  79.      * @since 2.9.0
  80.      */
  81.     @Override
  82.     public FileVisitResult accept(final Path file, final BasicFileAttributes attributes) {
  83.         return FileVisitResult.TERMINATE;
  84.     }

  85.     @Override
  86.     public IOFileFilter and(final IOFileFilter fileFilter) {
  87.         // FALSE AND expression <=> FALSE
  88.         return INSTANCE;
  89.     }

  90.     @Override
  91.     public IOFileFilter negate() {
  92.         return TrueFileFilter.INSTANCE;
  93.     }

  94.     @Override
  95.     public IOFileFilter or(final IOFileFilter fileFilter) {
  96.         // FALSE OR expression <=> expression
  97.         return fileFilter;
  98.     }

  99.     @Override
  100.     public String toString() {
  101.         return TO_STRING;
  102.     }
  103. }