/*
 * @(#)AllDirsExceptSvn.java
 *
 * Summary: FileFilter that accepts all directories, but not files, or subversion .svn _svn directories.
 *
 * Copyright: (c) 2003-2010 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.5+
 *
 * Created with: IntelliJ IDEA IDE.
 *
 * Version History:
 *  1.0 2009-05-04 - initial version. Written for Untouch to help it avoid meddling with Subversion files.
 */
package com.mindprod.filter;

import java.io.File;
import java.io.FilenameFilter;

/**
 * FileFilter that accepts all directories, but not files, or subversion .svn _svn directories.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2009-05-04 - initial version. Written for Untouch to help it avoid meddling with Subversion files.
 * @since 2009-05-04
 */
public final class AllDirsExceptSvn implements FilenameFilter
    {
    // ------------------------------ CONSTANTS ------------------------------

    /**
     * true if debugging. Enables debugging harness.
     */
    public static final boolean DEBUGGING = false;
    // -------------------------- PUBLIC INSTANCE  METHODS --------------------------

    /**
     * constructor
     */
    public AllDirsExceptSvn()
        {
        }

    /**
     * Select only files with that pass muster
     *
     * @param dir  the directory in which the file was found.
     * @param name the name of the file
     *
     * @return true if and only if the name should be included in the file list; false otherwise.
     */
    public boolean accept( File dir, String name )
        {
        File f = new File( dir, name );
        return f.isDirectory() && !name.equalsIgnoreCase( ".svn" ) && !name.equalsIgnoreCase( "_svn" );
        }

    // --------------------------- main() method ---------------------------

    /**
     * TEST harness
     *
     * @param args not used
     */
    public static void main( String[] args )
        {
        if ( DEBUGGING )
            {
            // just subdirectories of current directory
            FilenameFilter f = new AllDirsExceptSvn();

            String[] filenames = new File( "." ).list( f );

            for ( int i = 0; i < filenames.length; i++ )
                {
                System.out.println( filenames[ i ] );
                }
            }
        }
    }// end AllDirectoriesFilter
