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