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 *
028 * @since 1.0
029 * @see FileFilterUtils#falseFileFilter()
030 */
031public class FalseFileFilter implements IOFileFilter, Serializable {
032
033    private static final String TO_STRING = Boolean.FALSE.toString();
034
035    /**
036     * Singleton instance of false filter.
037     *
038     * @since 1.3
039     */
040    public static final IOFileFilter FALSE = new FalseFileFilter();
041
042    /**
043     * Singleton instance of false filter. Please use the identical FalseFileFilter.FALSE constant. The new name is more
044     * JDK 1.5 friendly as it doesn't clash with other values when using static imports.
045     */
046    public static final IOFileFilter INSTANCE = FALSE;
047
048    private static final long serialVersionUID = 6210271677940926200L;
049
050    /**
051     * Restrictive constructor.
052     */
053    protected FalseFileFilter() {
054    }
055
056    /**
057     * Returns false.
058     *
059     * @param file the file to check (ignored)
060     * @return false
061     */
062    @Override
063    public boolean accept(final File file) {
064        return false;
065    }
066
067    /**
068     * Returns false.
069     *
070     * @param dir the directory to check (ignored)
071     * @param name the file name (ignored)
072     * @return false
073     */
074    @Override
075    public boolean accept(final File dir, final String name) {
076        return false;
077    }
078
079    /**
080     * Returns false.
081     *
082     * @param file the file to check (ignored)
083     *
084     * @return false
085     * @since 2.9.0
086     */
087    @Override
088    public FileVisitResult accept(final Path file, final BasicFileAttributes attributes) {
089        return FileVisitResult.TERMINATE;
090    }
091
092    @Override
093    public IOFileFilter negate() {
094        return TrueFileFilter.INSTANCE;
095    }
096
097    @Override
098    public String toString() {
099        return TO_STRING;
100    }
101
102    @Override
103    public IOFileFilter and(final IOFileFilter fileFilter) {
104        // FALSE AND expression <=> FALSE
105        return INSTANCE;
106    }
107
108    @Override
109    public IOFileFilter or(final IOFileFilter fileFilter) {
110        // FALSE OR expression <=> expression
111        return fileFilter;
112    }
113}