NameFileFilterpublic class NameFileFilter extends AbstractFileFilter implements SerializableFilters filenames for a certain name.
For example, to print all files and directories in the
current directory whose name is Test :
File dir = new File(".");
String[] files = dir.list( new NameFileFilter("Test") );
for ( int i = 0; i < files.length; i++ ) {
System.out.println(files[i]);
}
|
Fields Summary |
---|
private final String[] | namesThe filenames to search for | private final IOCase | caseSensitivityWhether the comparison is case sensitive. |
Constructors Summary |
---|
public NameFileFilter(String name)Constructs a new case-sensitive name file filter for a single name.
this(name, null);
| public NameFileFilter(String name, IOCase caseSensitivity)Construct a new name file filter specifying case-sensitivity.
if (name == null) {
throw new IllegalArgumentException("The wildcard must not be null");
}
this.names = new String[] {name};
this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
| public NameFileFilter(String[] names)Constructs a new case-sensitive name file filter for an array of names.
The array is not cloned, so could be changed after constructing the
instance. This would be inadvisable however.
this(names, null);
| public NameFileFilter(String[] names, IOCase caseSensitivity)Constructs a new name file filter for an array of names specifying case-sensitivity.
The array is not cloned, so could be changed after constructing the
instance. This would be inadvisable however.
if (names == null) {
throw new IllegalArgumentException("The array of names must not be null");
}
this.names = names;
this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
| public NameFileFilter(List names)Constructs a new case-sensitive name file filter for a list of names.
this(names, null);
| public NameFileFilter(List names, IOCase caseSensitivity)Constructs a new name file filter for a list of names specifying case-sensitivity.
if (names == null) {
throw new IllegalArgumentException("The list of names must not be null");
}
this.names = (String[]) names.toArray(new String[names.size()]);
this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
|
Methods Summary |
---|
public boolean | accept(java.io.File file)Checks to see if the filename matches.
String name = file.getName();
for (int i = 0; i < this.names.length; i++) {
if (caseSensitivity.checkEquals(name, names[i])) {
return true;
}
}
return false;
| public boolean | accept(java.io.File file, java.lang.String name)Checks to see if the filename matches.
for (int i = 0; i < names.length; i++) {
if (caseSensitivity.checkEquals(name, names[i])) {
return true;
}
}
return false;
| public java.lang.String | toString()Provide a String representaion of this file filter.
StringBuffer buffer = new StringBuffer();
buffer.append(super.toString());
buffer.append("(");
if (names != null) {
for (int i = 0; i < names.length; i++) {
if (i > 0) {
buffer.append(",");
}
buffer.append(names[i]);
}
}
buffer.append(")");
return buffer.toString();
|
|