org.apache.commons.io.filefilter
Class WildcardFilter

java.lang.Object
  |
  +--org.apache.commons.io.filefilter.AbstractFileFilter
        |
        +--org.apache.commons.io.filefilter.WildcardFilter
All Implemented Interfaces:
java.io.FileFilter, java.io.FilenameFilter, IOFileFilter

public class WildcardFilter
extends AbstractFileFilter

Filters files using supplied wildcard(s).

See org.apache.commons.io.find.FilenameUtils.wildcardMatch() for wildcard matching rules

e.g.

 File dir = new File(".");
 FileFilter fileFilter = new WildcardFilter("*test*.java~*~");
 File[] files = dir.listFiles(fileFilter);
 for (int i = 0; i < files.length; i++) {
   System.out.println(files[i]);
 }
 

Since:
Commons IO 1.1
Version:
$Revision: 155419 $ $Date: 2005-02-26 13:02:41 +0000 (Sat, 26 Feb 2005) $
Author:
Jason Anderson

Field Summary
private  java.lang.String[] wildcards
          The wildcards that will be used to match filenames
 
Constructor Summary
WildcardFilter(java.util.List wildcards)
          Construct a new wildcard filter for a list of wildcards
WildcardFilter(java.lang.String wildcard)
          Construct a new wildcard filter for a single wildcard
WildcardFilter(java.lang.String[] wildcards)
          Construct a new wildcard filter for an array of wildcards
 
Method Summary
 boolean accept(java.io.File file)
          Checks to see if the filename matches one of the wildcards.
 boolean accept(java.io.File dir, java.lang.String name)
          Checks to see if the filename matches one of the wildcards.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

wildcards

private java.lang.String[] wildcards
The wildcards that will be used to match filenames
Constructor Detail

WildcardFilter

public WildcardFilter(java.lang.String wildcard)
Construct a new wildcard filter for a single wildcard
Parameters:
wildcard - wildcard to match
Throws:
java.lang.IllegalArgumentException - if the pattern is null

WildcardFilter

public WildcardFilter(java.lang.String[] wildcards)
Construct a new wildcard filter for an array of wildcards
Parameters:
wildcards - wildcards to match
Throws:
java.lang.IllegalArgumentException - if the pattern array is null

WildcardFilter

public WildcardFilter(java.util.List wildcards)
Construct a new wildcard filter for a list of wildcards
Parameters:
wildcards - list of wildcards to match
Throws:
java.lang.IllegalArgumentException - if the pattern list is null
ClassCastException - if the list does not contain Strings
Method Detail

accept

public boolean accept(java.io.File dir,
                      java.lang.String name)
Checks to see if the filename matches one of the wildcards.
Overrides:
accept in class AbstractFileFilter
Parameters:
dir - the file directory
name - the filename
Returns:
true if the filename matches one of the wildcards

accept

public boolean accept(java.io.File file)
Checks to see if the filename matches one of the wildcards.
Overrides:
accept in class AbstractFileFilter
Parameters:
file - the file to check
Returns:
true if the filename matches one of the wildcards