001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.io.filefilter;
018
019import java.io.File;
020import java.io.Serializable;
021import java.nio.file.FileVisitResult;
022import java.nio.file.Path;
023import java.nio.file.attribute.BasicFileAttributes;
024
025/**
026 * A file filter that always returns false.
027 * <h2>Deprecating Serialization</h2>
028 * <p>
029 * <em>Serialization is deprecated and will be removed in 3.0.</em>
030 * </p>
031 *
032 * @since 1.0
033 * @see FileFilterUtils#falseFileFilter()
034 */
035public class FalseFileFilter implements IOFileFilter, Serializable {
036
037    private static final String TO_STRING = Boolean.FALSE.toString();
038
039    /**
040     * Singleton instance of false filter.
041     *
042     * @since 1.3
043     */
044    public static final IOFileFilter FALSE = new FalseFileFilter();
045
046    /**
047     * Singleton instance of false filter. Please use the identical FalseFileFilter.FALSE constant. The new name is more
048     * JDK 1.5 friendly as it doesn't clash with other values when using static imports.
049     */
050    public static final IOFileFilter INSTANCE = FALSE;
051
052    private static final long serialVersionUID = 6210271677940926200L;
053
054    /**
055     * Restrictive constructor.
056     */
057    protected FalseFileFilter() {
058    }
059
060    /**
061     * Returns false.
062     *
063     * @param file the file to check (ignored)
064     * @return false
065     */
066    @Override
067    public boolean accept(final File file) {
068        return false;
069    }
070
071    /**
072     * Returns false.
073     *
074     * @param dir the directory to check (ignored)
075     * @param name the file name (ignored)
076     * @return false
077     */
078    @Override
079    public boolean accept(final File dir, final String name) {
080        return false;
081    }
082
083    /**
084     * Returns false.
085     *
086     * @param file the file to check (ignored)
087     *
088     * @return false
089     * @since 2.9.0
090     */
091    @Override
092    public FileVisitResult accept(final Path file, final BasicFileAttributes attributes) {
093        return FileVisitResult.TERMINATE;
094    }
095
096    @Override
097    public IOFileFilter and(final IOFileFilter fileFilter) {
098        // FALSE AND expression <=> FALSE
099        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}