public class WildcardFilter extends Object implements FileFilter, FilenameFilter, Serializable
accept(String)
.
The wildcard matcher uses the characters '?' and '*' to represent a single or multiple wildcard characters.
File dir = new File("."); FileFilter fileFilter = new WildcardFileFilter("*test*.java"); for (File file: dir.listFiles(fileFilter)) { ... }
Modifier and Type | Field and Description |
---|---|
static String |
ACCEPT_ALL
Path pattern accepting all files.
|
private String |
pattern
Pattern used to match file names and strings.
|
private static long |
serialVersionUID
Java serialization version.
|
Constructor and Description |
---|
WildcardFilter(String pattern)
Construct a new case-sensitive wildcard filter instance.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(File file)
Test if name of the file matches this filter pattern.
|
boolean |
accept(File dir,
String name)
Test if file name matches this filter pattern.
|
boolean |
accept(String string)
Returns true if string value matches this filter pattern.
|
private static boolean |
match(String string,
String pattern)
Test if string value matches given pattern.
|
private static String[] |
tokenize(String string)
Splits a string into a number of tokens.
|
String |
toString()
Instance string representation.
|
private static final long serialVersionUID
public static final String ACCEPT_ALL
private final String pattern
public WildcardFilter(String pattern)
pattern
- pattern used to match file names and strings.IllegalArgumentException
- if the pattern is null or empty.public boolean accept(File dir, String name)
If name
argument is null or empty this predicate returns false.
accept
in interface FilenameFilter
dir
- unused file directory, for interface compatibility.name
- the file name, null or empty accepted.name
argument matches this filter pattern.public boolean accept(File file)
file
argument is null.accept
in interface FileFilter
file
- the file to check, null accepted.public boolean accept(String string)
string
argument is null or empty.string
- string value, null or empty accepted.public String toString()
private static boolean match(String string, String pattern)
string
argument is null or empty. Pattern
argument is guaranteed by this class logic to be not null and not empty.string
- string value to match against pattern, null or empty accepted,pattern
- not null or empty pattern.Copyright © 2018. All rights reserved.