Accepts a selection if it is acceptable to both of two FilenameFilters
import java.io.File;
import java.io.FilenameFilter;
/**
* Accepts a selection if it is acceptable to both of two {@link FilenameFilter}s.
* This takes two {@link FilenameFilter}s as input.
*
* <p>Eg., to print all files beginning with <code>A</code> and ending with <code>.java</code>:</p>
*
* <pre>
* File dir = new File(".");
* String[] files = dir.list( new AndFileFilter(
* new PrefixFileFilter("A"),
* new ExtensionFileFilter(".java")
* )
* );
* for ( int i=0; i<files.length; i++ )
* {
* System.out.println(files[i]);
* }
* </pre>
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $
* @since 4.0
*/
public class AndFileFilter
implements FilenameFilter
{
private final FilenameFilter m_filter1;
private final FilenameFilter m_filter2;
public AndFileFilter( final FilenameFilter filter1, final FilenameFilter filter2 )
{
m_filter1 = filter1;
m_filter2 = filter2;
}
public boolean accept( final File file, final String name )
{
return m_filter1.accept( file, name ) && m_filter2.accept( file, name );
}
}
Related examples in the same category