    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 *      https://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 true.
    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#trueFileFilter()
    034 */
    035public class TrueFileFilter implements IOFileFilter, Serializable {
    036
    037    private static final String TO_STRING = Boolean.TRUE.toString();
    038
    039    private static final long serialVersionUID = 8782512160909720199L;
    040
    041    /**
    042     * Singleton instance of true filter.
    043     *
    044     * @since 1.3
    045     */
    046    public static final IOFileFilter TRUE = new TrueFileFilter();
    047
    048    /**
    049     * Singleton instance of true filter. Please use the identical TrueFileFilter.TRUE constant. The new name is more
    050     * JDK 1.5 friendly as it doesn't clash with other values when using static imports.
    051     */
    052    public static final IOFileFilter INSTANCE = TRUE;
    053
    054    /**
    055     * Restrictive constructor.
    056     */
    057    protected TrueFileFilter() {
    058    }
    059
    060    /**
    061     * Returns true.
    062     *
    063     * @param file the file to check (ignored).
    064     * @return true.
    065     */
    066    @Override
    067    public boolean accept(final File file) {
    068        return true;
    069    }
    070
    071    /**
    072     * Returns true.
    073     *
    074     * @param dir the directory to check (ignored).
    075     * @param name the file name (ignored).
    076     * @return true.
    077     */
    078    @Override
    079    public boolean accept(final File dir, final String name) {
    080        return true;
    081    }
    082
    083    /**
    084     * Returns true.
    085     *
    086     * @param file the file to check (ignored).
    087     * @param attributes the path's basic attributes (may be null).
    088     * @return true.
    089     * @since 2.9.0
    090     */
    091    @Override
    092    public FileVisitResult accept(final Path file, final BasicFileAttributes attributes) {
    093        return FileVisitResult.CONTINUE;
    094    }
    095
    096    @Override
    097    public IOFileFilter and(final IOFileFilter fileFilter) {
    098        // TRUE AND expression <=> expression
    099        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}