|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.filechooser.FileFilter
bb.io.filefilter.CompoundFilter
public class CompoundFilter
Meta filter whose accept
method incorporates all the constraints of all the file filters that it was constructed with.
Note that RegexFilter
and SuffixFilter
can be viewed as specialized types of compound filters:
each has a set of criteria that are connected by an implicit logical OR.
Using/subclassing RegexFilter or SuffixFilter is therefore more convenient than this class if that is the desired behavior.
In contrast, this class offers much more flexibility: any type of filters can be used,
and the filters can be connected by logical AND
as well logical OR
.
Note that this class is both a subclass of javax.swing.filechooser.FileFilter
(so that it can be passed to JFileChooser
),
as well as an implementation of java.io.FileFilter
(so that it is suitable as an argument to File.listFiles
).
This class is multithread safe if all the elements in its filters
field are multithread safe,
since other than possible deep state in those elements,
it is immutable.
In particular, it is always properly constructed,
all of its fields are final,
and none of their state can be changed after construction except possibly any deep state inside filters' elements.
See p. 53 of Java Concurrency In Practice for more discussion.
Nested Class Summary | |
---|---|
private static class |
CompoundFilter.LogicMode
Enum of all the supported modes for applying the individual filters. |
static class |
CompoundFilter.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private Set<FileFilter> |
filters
FileFilters which will be used in accept and getDescription . |
private CompoundFilter.LogicMode |
logicMode
|
Constructor Summary | |
---|---|
protected |
CompoundFilter(CompoundFilter.LogicMode logicMode,
FileFilter... filters)
Constructor. |
Method Summary | |
---|---|
boolean |
accept(File file)
Reports whether or not file is accepted by this instance. |
String |
getDescription()
Returns a description of this filter. |
private String |
getDescription(FileFilter filter)
|
private String |
getLogicModeDescription()
|
static CompoundFilter |
makeAnd(FileFilter... filters)
Returns a new CompoundFilter instance that connects the elements of filters via logical AND . |
static CompoundFilter |
makeOr(FileFilter... filters)
Returns a new CompoundFilter instance that connects the elements of filters via logical OR . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final CompoundFilter.LogicMode logicMode
private final Set<FileFilter> filters
accept
and getDescription
.
Constructor Detail |
---|
protected CompoundFilter(CompoundFilter.LogicMode logicMode, FileFilter... filters) throws IllegalArgumentException
logicMode
- assigned to the logicMode
fieldfilters
- assigned to the filters
field;
for top performance, place the most frequently encountered patterns earliest in the array
IllegalArgumentException
- if logicMode == null; filters == null; filters.length == 0Method Detail |
---|
public static CompoundFilter makeAnd(FileFilter... filters) throws IllegalArgumentException
logical AND
.
filters
- assigned to the filters
field;
for top performance, place the most frequently encountered patterns earliest in the array
IllegalArgumentException
- if filters == null; filters.length == 0public static CompoundFilter makeOr(FileFilter... filters) throws IllegalArgumentException
logical OR
.
filters
- assigned to the filters
field;
for top performance, place the most frequently encountered patterns earliest in the array
IllegalArgumentException
- if filters == null; filters.length == 0public boolean accept(File file) throws IllegalArgumentException, SecurityException, IllegalStateException
filters
according to logicMode
.
accept
in interface FileFilter
accept
in class FileFilter
IllegalArgumentException
- if file is null
SecurityException
- if a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file
IllegalStateException
- if the class finds itself in an unexpected statepublic String getDescription()
filters
.
getDescription
in class FileFilter
private String getLogicModeDescription() throws IllegalStateException
IllegalStateException
private String getDescription(FileFilter filter)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |