public class ExtendedFileFilter extends java.lang.Object implements java.io.FilenameFilter, IObjectFilter<java.lang.Object>
Modifier and Type | Field and Description |
---|---|
protected static int |
DIR_CHECK_NAME |
protected static int |
DIR_EXCLUDE |
protected static int |
DIR_INCLUDE |
static java.lang.String |
PATTERN_SEPARATOR
The character to be used to separate filename patterns (';') as String.
|
Constructor and Description |
---|
ExtendedFileFilter()
Initialize the new instance with default values.
|
ExtendedFileFilter(boolean restrictive)
Initialize the new instance with the option of a more restrictive handling
of wildcard matching.
|
ExtendedFileFilter(char wildcardForDigits)
Initialize the new instance with a wildcard character for digits.
|
ExtendedFileFilter(char wildcardForDigits,
boolean restrictive)
Initialize the new instance with a wildcard character for digits in
filenames and the option of a more restrictive handling
of wildcard matching.
|
ExtendedFileFilter(IStringFilter... nameFilters)
Initialize the new instance with filters.
|
ExtendedFileFilter(java.lang.String patternList)
Initialize the new instance with patterns.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.io.File dir,
java.lang.String name)
Tests if a specified file should be included in a file list.
|
void |
addNameFilters(IStringFilter... stringFilters) |
void |
addPattern(java.lang.String pattern)
Adds a pattern.
|
void |
addPattern(java.lang.String pattern,
boolean ignoreCase)
Adds a pattern.
|
void |
addPattern(java.lang.String pattern,
boolean ignoreCase,
char digitWildcardChar)
Adds a pattern.
|
void |
addPattern(java.lang.String pattern,
char digitWildcardChar)
Adds a pattern.
|
void |
addPatterns(java.lang.String patternList)
Adds one or more patterns separated by semi-colon (';').
|
void |
alwaysExcludeDirectories()
Sets the filter to never accept directories.
|
void |
alwaysIncludeDirectories()
Sets the filter to always accept directories, even if they don't match
a given pattern.
|
protected boolean |
checkAgainstStringFilters(java.lang.String name) |
void |
checkNameOfDirectories()
Sets the filter to only accept directories that match a defined pattern.
|
protected StringPattern |
createStringPattern(java.lang.String pattern,
boolean ignoreCase) |
protected java.lang.String[] |
extractPatterns(java.lang.String pattern) |
protected java.lang.Character |
getDigitWildcard() |
protected char |
getDigitWildcardChar() |
protected int |
getDirHandling() |
protected boolean |
getRestrictiveMode() |
protected java.util.List<IStringFilter> |
getStringFilterList() |
protected boolean |
hasDigitWildcard() |
boolean |
matches(java.lang.Object object)
Returns if this filter matches the given object.
|
protected boolean |
matchesFile(java.io.File file) |
boolean |
mustExcludeDirectories()
Returns true if the filter never accepts directories.
|
boolean |
mustIncludeDirectories()
Returns true if the filter always accepts directories, even if they don't match
a given pattern.
|
protected void |
postAcceptCheck(java.io.File dir,
java.lang.String filename,
java.io.File file,
boolean accepted)
This method gets called after the accept check had happened.
|
protected void |
setDigitWildcard(java.lang.Character newValue) |
protected void |
setDirHandling(int newValue) |
protected void |
setRestrictiveMode(boolean newValue) |
protected void |
setStringFilterList(java.util.List<IStringFilter> newValue) |
protected StringUtil |
str() |
public static final java.lang.String PATTERN_SEPARATOR
protected static final int DIR_CHECK_NAME
protected static final int DIR_INCLUDE
protected static final int DIR_EXCLUDE
public ExtendedFileFilter()
public ExtendedFileFilter(java.lang.String patternList)
patternList
- A list of patterns (may be just one)addPatterns(String)
public ExtendedFileFilter(IStringFilter... nameFilters)
nameFilters
- An optional array of name filters (must not be null).public ExtendedFileFilter(char wildcardForDigits)
wildcardForDigits
- The character that stands for any digit (0-9) in a filenamepublic ExtendedFileFilter(boolean restrictive)
Example:
restrictive=true => "text.doc" does NOT match the pattern "text*.doc"
restrictive=false => "text.doc" does match the pattern "text*.doc"
restrictive
- To restrict the match of '*' to at least one characterpublic ExtendedFileFilter(char wildcardForDigits, boolean restrictive)
See other constructor for examples.
wildcardForDigits
- The character that stands for any digit (0-9) in a filenamerestrictive
- To restrict the match of '*' to at least one characterpublic void addPattern(java.lang.String pattern)
pattern
- The pattern string containing optional wildcards ( '*', '?' )public void addPattern(java.lang.String pattern, char digitWildcardChar)
A patterb "XX-####.log" with a digitWildcard set to '#' wil match to "XX-2000.log" and "XX-7376.log" but not to "XX-C363.log" and "XX-dddd.log".
pattern
- The pattern string containing optional wildcards ( '*', '?' )digitWildcardChar
- The character that will be treated as wildcard for digits ('0'-'9')public void addPattern(java.lang.String pattern, boolean ignoreCase)
pattern
- The pattern string containing optional wildcards ( '*', '?' )ignoreCase
- If true, all character comparisons are ignoring uppercase/lowercasepublic void addPattern(java.lang.String pattern, boolean ignoreCase, char digitWildcardChar)
pattern
- The pattern string containing optional wildcards ( '*', '?' )ignoreCase
- If true, all character comparisons are ignoring uppercase/lowercasedigitWildcardChar
- The character that will be treated as wildcard for digits ('0'-'9')public void addPatterns(java.lang.String patternList)
patternList
- The list of filename patternspublic void addNameFilters(IStringFilter... stringFilters)
public void checkNameOfDirectories()
public void alwaysIncludeDirectories()
public void alwaysExcludeDirectories()
public boolean accept(java.io.File dir, java.lang.String name)
accept
in interface java.io.FilenameFilter
dir
- the directory in which the file was found.name
- the name of the file.public boolean matches(java.lang.Object object)
matches
in interface IObjectFilter<java.lang.Object>
object
- Any objectpublic boolean mustIncludeDirectories()
public boolean mustExcludeDirectories()
protected void postAcceptCheck(java.io.File dir, java.lang.String filename, java.io.File file, boolean accepted)
dir
- The directory in which the file is locatedfilename
- The name of the file without pathfile
- The combined directory and filenameaccepted
- The result of the acceptance checkprotected boolean checkAgainstStringFilters(java.lang.String name)
protected StringPattern createStringPattern(java.lang.String pattern, boolean ignoreCase)
protected java.lang.String[] extractPatterns(java.lang.String pattern)
protected char getDigitWildcardChar()
protected boolean hasDigitWildcard()
protected boolean matchesFile(java.io.File file)
protected java.util.List<IStringFilter> getStringFilterList()
protected void setStringFilterList(java.util.List<IStringFilter> newValue)
protected int getDirHandling()
protected void setDirHandling(int newValue)
protected boolean getRestrictiveMode()
protected void setRestrictiveMode(boolean newValue)
protected java.lang.Character getDigitWildcard()
protected void setDigitWildcard(java.lang.Character newValue)
protected StringUtil str()