org.apache.commons.io.filefilter
Class WildcardFilter

java.lang.Object
  extended byorg.apache.commons.io.filefilter.AbstractFileFilter
      extended byorg.apache.commons.io.filefilter.WildcardFilter
All Implemented Interfaces:
FileFilter, 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) $

Constructor Summary
WildcardFilter(List wildcards)
          Construct a new wildcard filter for a list of wildcards
WildcardFilter(String wildcard)
          Construct a new wildcard filter for a single wildcard
WildcardFilter(String[] wildcards)
          Construct a new wildcard filter for an array of wildcards
 
Method Summary
 boolean accept(File file)
          Checks to see if the filename matches one of the wildcards.
 boolean accept(File dir, 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, toString, wait, wait, wait
 

Constructor Detail

WildcardFilter

public WildcardFilter(String wildcard)
Construct a new wildcard filter for a single wildcard

Parameters:
wildcard - wildcard to match
Throws:
IllegalArgumentException - if the pattern is null

WildcardFilter

public WildcardFilter(String[] wildcards)
Construct a new wildcard filter for an array of wildcards

Parameters:
wildcards - wildcards to match
Throws:
IllegalArgumentException - if the pattern array is null

WildcardFilter

public WildcardFilter(List wildcards)
Construct a new wildcard filter for a list of wildcards

Parameters:
wildcards - list of wildcards to match
Throws:
IllegalArgumentException - if the pattern list is null
ClassCastException - if the list does not contain Strings
Method Detail

accept

public boolean accept(File dir,
                      String name)
Checks to see if the filename matches one of the wildcards.

Specified by:
accept in interface IOFileFilter
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(File file)
Checks to see if the filename matches one of the wildcards.

Specified by:
accept in interface IOFileFilter
Overrides:
accept in class AbstractFileFilter
Parameters:
file - the file to check
Returns:
true if the filename matches one of the wildcards


Copyright © 2002-2006 The Apache Software Foundation. All Rights Reserved.