/*
 * @(#)AvoidJunkFilter.java
 *
 * Summary: Filter to permit only non-junk files.
 *
 * Copyright: (c) 2009-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-15 - initial version
 */
package com.mindprod.filter;

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

/**
 * Filter to permit only non-junk files.
 * <p/>
 * accept only non-junk files.
 * Can define junk files by name, extension, starts with or endsWith lists, the same as you would JunkFilter.
 * Returns false for all directories.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2009-05-15 - initial version
 * @since 2009-05-15
 */
public final class AvoidJunkFilter extends JunkFilter implements FilenameFilter
    {
    // -------------------------- PUBLIC INSTANCE  METHODS --------------------------

    /**
     * Defines which filenames and extensions are considered junk, to be deleted.
     */
    public AvoidJunkFilter()
        {
        }

    /**
     * Accept only junk files to be deleted.
     *
     * @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 )
        {
        if ( dir == null || name == null || new File( dir, name ).isDirectory() )
            {
            return false;
            }
        else
            {
            return !super.accept( dir, name );
            }
        }
    }
