Package org.apache.commons.io.filefilter
Class AndFileFilter
- java.lang.Object
-
- org.apache.commons.io.filefilter.AbstractFileFilter
-
- org.apache.commons.io.filefilter.AndFileFilter
-
- All Implemented Interfaces:
FileFilter
,FilenameFilter
,Serializable
,FileVisitor<Path>
,PathFilter
,PathVisitor
,ConditionalFileFilter
,IOFileFilter
public class AndFileFilter extends AbstractFileFilter implements ConditionalFileFilter, Serializable
AFileFilter
providing conditional AND logic across a list of file filters. This filter returnstrue
if all filters in the list returntrue
. Otherwise, it returnsfalse
. Checking of the file filter list stops when the first filter returnsfalse
.- Since:
- 1.0
- See Also:
FileFilterUtils.and(IOFileFilter...)
, Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.apache.commons.io.filefilter.IOFileFilter
EMPTY_STRING_ARRAY
-
-
Constructor Summary
Constructors Constructor Description AndFileFilter()
Constructs a new empty instance.AndFileFilter(List<IOFileFilter> fileFilters)
Constructs a new instance ofAndFileFilter
with the specified list of filters.AndFileFilter(IOFileFilter... fileFilters)
Constructs a new instance for the give filters.AndFileFilter(IOFileFilter filter1, IOFileFilter filter2)
Constructs a new file filter that ANDs the result of other filters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(File file)
Checks to see if the File should be accepted by this filter.boolean
accept(File file, String name)
Checks to see if the File should be accepted by this filter.FileVisitResult
accept(Path file, BasicFileAttributes attributes)
Checks to see if the Path should be accepted by this filter.void
addFileFilter(IOFileFilter fileFilter)
Adds the specified file filter to the list of file filters at the end of the list.void
addFileFilter(IOFileFilter... fileFilters)
Adds the given file filters.List<IOFileFilter>
getFileFilters()
Gets this conditional file filter's list of file filters.boolean
removeFileFilter(IOFileFilter ioFileFilter)
Removes the specified file filter.void
setFileFilters(List<IOFileFilter> fileFilters)
Sets the list of file filters, replacing any previously configured file filters on this filter.String
toString()
Provide a String representation of this file filter.-
Methods inherited from class org.apache.commons.io.filefilter.AbstractFileFilter
postVisitDirectory, preVisitDirectory, visitFile, visitFileFailed
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.io.filefilter.IOFileFilter
and, negate, or
-
-
-
-
Constructor Detail
-
AndFileFilter
public AndFileFilter()
Constructs a new empty instance.- Since:
- 1.1
-
AndFileFilter
public AndFileFilter(IOFileFilter filter1, IOFileFilter filter2)
Constructs a new file filter that ANDs the result of other filters.- Parameters:
filter1
- the first filter, must second be nullfilter2
- the first filter, must not be null- Throws:
IllegalArgumentException
- if either filter is null
-
AndFileFilter
public AndFileFilter(IOFileFilter... fileFilters)
Constructs a new instance for the give filters.- Parameters:
fileFilters
- filters to OR.- Since:
- 2.9.0
-
AndFileFilter
public AndFileFilter(List<IOFileFilter> fileFilters)
Constructs a new instance ofAndFileFilter
with the specified list of filters.- Parameters:
fileFilters
- a List of IOFileFilter instances, copied.- Since:
- 1.1
-
-
Method Detail
-
accept
public boolean accept(File file)
Checks to see if the File should be accepted by this filter.- Specified by:
accept
in interfaceFileFilter
- Specified by:
accept
in interfaceIOFileFilter
- Overrides:
accept
in classAbstractFileFilter
- Parameters:
file
- the File to check- Returns:
- true if this file matches the test
-
accept
public boolean accept(File file, String name)
Checks to see if the File should be accepted by this filter.- Specified by:
accept
in interfaceFilenameFilter
- Specified by:
accept
in interfaceIOFileFilter
- Overrides:
accept
in classAbstractFileFilter
- Parameters:
file
- the directory File to checkname
- the file name within the directory to check- Returns:
- true if this file matches the test
-
accept
public FileVisitResult accept(Path file, BasicFileAttributes attributes)
Checks to see if the Path should be accepted by this filter.- Specified by:
accept
in interfaceIOFileFilter
- Specified by:
accept
in interfacePathFilter
- Parameters:
file
- the Path to check.attributes
- the file's basic attributes (TODO may be null).- Returns:
- true if this path matches the test.
- Since:
- 2.9.0
-
addFileFilter
public void addFileFilter(IOFileFilter fileFilter)
Adds the specified file filter to the list of file filters at the end of the list.- Specified by:
addFileFilter
in interfaceConditionalFileFilter
- Parameters:
fileFilter
- the filter to be added
-
addFileFilter
public void addFileFilter(IOFileFilter... fileFilters)
Adds the given file filters.- Parameters:
fileFilters
- the filters to add.- Since:
- 2.9.0
-
getFileFilters
public List<IOFileFilter> getFileFilters()
Gets this conditional file filter's list of file filters.- Specified by:
getFileFilters
in interfaceConditionalFileFilter
- Returns:
- the file filter list
-
removeFileFilter
public boolean removeFileFilter(IOFileFilter ioFileFilter)
Removes the specified file filter.- Specified by:
removeFileFilter
in interfaceConditionalFileFilter
- Parameters:
ioFileFilter
- filter to be removed- Returns:
true
if the filter was found in the list,false
otherwise
-
setFileFilters
public void setFileFilters(List<IOFileFilter> fileFilters)
Sets the list of file filters, replacing any previously configured file filters on this filter.- Specified by:
setFileFilters
in interfaceConditionalFileFilter
- Parameters:
fileFilters
- the list of filters
-
toString
public String toString()
Provide a String representation of this file filter.- Overrides:
toString
in classAbstractFileFilter
- Returns:
- a String representation
-
-