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     */
017    package org.apache.commons.io.filefilter;
018    
019    import java.io.File;
020    import java.io.Serializable;
021    
022    /**
023     * This filter accepts <code>File</code>s that are directories.
024     * <p>
025     * For example, here is how to print out a list of the 
026     * current directory's subdirectories:
027     *
028     * <pre>
029     * File dir = new File(".");
030     * String[] files = dir.list( DirectoryFileFilter.INSTANCE );
031     * for ( int i = 0; i &lt; files.length; i++ ) {
032     *     System.out.println(files[i]);
033     * }
034     * </pre>
035     *
036     * @since Commons IO 1.0
037     * @version $Revision: 1005099 $ $Date: 2010-10-06 12:13:01 -0400 (Wed, 06 Oct 2010) $
038     *
039     * @author Stephen Colebourne
040     * @author Peter Donald
041     * @see FileFilterUtils#directoryFileFilter()
042     */
043    public class DirectoryFileFilter extends AbstractFileFilter implements Serializable {
044    
045        /**
046         * Singleton instance of directory filter.
047         * @since Commons IO 1.3
048         */
049        public static final IOFileFilter DIRECTORY = new DirectoryFileFilter();
050        /**
051         * Singleton instance of directory filter.
052         * Please use the identical DirectoryFileFilter.DIRECTORY constant.
053         * The new name is more JDK 1.5 friendly as it doesn't clash with other
054         * values when using static imports.
055         */
056        public static final IOFileFilter INSTANCE = DIRECTORY;
057    
058        /**
059         * Restrictive consructor.
060         */
061        protected DirectoryFileFilter() {
062        }
063    
064        /**
065         * Checks to see if the file is a directory.
066         *
067         * @param file  the File to check
068         * @return true if the file is a directory
069         */
070        @Override
071        public boolean accept(File file) {
072            return file.isDirectory();
073        }
074    
075    }