org.clapper.util.io
Class OrFileFilter

java.lang.Object
  extended by org.clapper.util.io.OrFileFilter
All Implemented Interfaces:
java.io.FileFilter

public final class OrFileFilter
extends java.lang.Object
implements java.io.FileFilter

An OrFileFilter logically ORs other java.io.FileFilter objects. When its accept() method is called, the OrFileFilter object passes the file through the contained filters. The file is accepted if it is accepted by any of the contained filters. This class conceptually provides a logical "OR" operator for file filters.

The contained filters are applied in the order they were added to the OrFileFilter object. This class's accept() method stops looping over the contained filters as soon as it encounters one whose accept() method returns true (implementing a "short-circuited OR" operation.)

Version:
$Revision: 5812 $
Author:
Copyright © 2004-2007 Brian M. Clapper
See Also:
FileFilter, AndFileFilter, NotFileFilter, OrFilenameFilter, RegexFileFilter

Constructor Summary
OrFileFilter()
          Construct a new OrFileFilter with no contained filters.
OrFileFilter(java.io.FileFilter... filters)
          Construct a new OrFileFilter with two contained filters.
 
Method Summary
 boolean accept(java.io.File file)
          Determine whether a file is to be accepted or not, based on the contained filters.
 OrFileFilter addFilter(java.io.FileFilter filter)
          Add a filter to the set of contained filters.
 void removeFilter(java.io.FileFilter filter)
          Remove a filter from the set of contained filters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OrFileFilter

public OrFileFilter()
Construct a new OrFileFilter with no contained filters.


OrFileFilter

public OrFileFilter(java.io.FileFilter... filters)
Construct a new OrFileFilter with two contained filters. Additional filters may be added later, via calls to the addFilter() method.

Parameters:
filters - filters to add
Method Detail

addFilter

public OrFileFilter addFilter(java.io.FileFilter filter)
Add a filter to the set of contained filters.

Parameters:
filter - the FileFilter to add.
Returns:
this object, to permit chained calls.
See Also:
removeFilter(java.io.FileFilter)

removeFilter

public void removeFilter(java.io.FileFilter filter)
Remove a filter from the set of contained filters.

Parameters:
filter - the FileFilter to remove.
See Also:
addFilter(java.io.FileFilter)

accept

public boolean accept(java.io.File file)
Determine whether a file is to be accepted or not, based on the contained filters. The file is accepted if any one of the contained filters accepts it. This method stops looping over the contained filters as soon as it encounters one whose accept() method returns false (implementing a "short-circuited AND" operation.)

If the set of contained filters is empty, then this method returns true.

Specified by:
accept in interface java.io.FileFilter
Parameters:
file - The file to check for acceptance
Returns:
true if the file matches, false if it doesn't


Copyright © 2004-2007 Brian M. Clapper. All Rights Reserved.