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;
021
022/**
023 * This filter accepts <code>File</code>s that are hidden.
024 * <p>
025 * Example, showing how to print out a list of the
026 * current directory's <i>hidden</i> files:
027 *
028 * <pre>
029 * File dir = new File(".");
030 * String[] files = dir.list( HiddenFileFilter.HIDDEN );
031 * for ( int i = 0; i &lt; files.length; i++ ) {
032 *     System.out.println(files[i]);
033 * }
034 * </pre>
035 *
036 * <p>
037 * Example, showing how to print out a list of the
038 * current directory's <i>visible</i> (i.e. not hidden) files:
039 *
040 * <pre>
041 * File dir = new File(".");
042 * String[] files = dir.list( HiddenFileFilter.VISIBLE );
043 * for ( int i = 0; i &lt; files.length; i++ ) {
044 *     System.out.println(files[i]);
045 * }
046 * </pre>
047 *
048 * @since 1.3
049 * @version $Id: HiddenFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
050 */
051public class HiddenFileFilter extends AbstractFileFilter implements Serializable {
052
053    private static final long serialVersionUID = 8930842316112759062L;
054
055    /** Singleton instance of <i>hidden</i> filter */
056    public static final IOFileFilter HIDDEN  = new HiddenFileFilter();
057
058    /** Singleton instance of <i>visible</i> filter */
059    public static final IOFileFilter VISIBLE = new NotFileFilter(HIDDEN);
060
061    /**
062     * Restrictive consructor.
063     */
064    protected HiddenFileFilter() {
065    }
066
067    /**
068     * Checks to see if the file is hidden.
069     *
070     * @param file  the File to check
071     * @return {@code true} if the file is
072     *  <i>hidden</i>, otherwise {@code false}.
073     */
074    @Override
075    public boolean accept(final File file) {
076        return file.isHidden();
077    }
078
079}