messif.utility
Class WildcardFileFilter

java.lang.Object
  extended by messif.utility.WildcardFileFilter
All Implemented Interfaces:
java.io.FileFilter, java.io.FilenameFilter

public class WildcardFileFilter
extends java.lang.Object
implements java.io.FileFilter, java.io.FilenameFilter

This class provides an implementation of FileFilter and FilenameFilter interfaces that can match filenames using a Glob pattern. The pattern can use *, ?, [abc-z] placeholders. The directory part of matched files is not checked.


Constructor Summary
WildcardFileFilter(java.lang.String pattern)
          Creates a new instance of WildcardFileFilter for the given pattern.
 
Method Summary
 boolean accept(java.io.File pathname)
           
 boolean accept(java.io.File dir, java.lang.String name)
           
static int getFilenameGlobPosition(java.lang.String name)
          Returns the position of the first glob char in the given filename.
 boolean match(java.lang.String name)
          Returns if the specified name matches this wildcard.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WildcardFileFilter

public WildcardFileFilter(java.lang.String pattern)
                   throws java.lang.NullPointerException
Creates a new instance of WildcardFileFilter for the given pattern. The pattern can use
*, ?, [abc-z]
placeholders.

Parameters:
pattern - the Glob pattern to use
Throws:
java.lang.NullPointerException - if the pattern was null
Method Detail

getFilenameGlobPosition

public static int getFilenameGlobPosition(java.lang.String name)
Returns the position of the first glob char in the given filename.

Parameters:
name - the file name in which to get the glob char
Returns:
the position of the first glob char in the given filename or -1 if the name does not contain any glob char

match

public boolean match(java.lang.String name)
Returns if the specified name matches this wildcard.

Parameters:
name - the string to match
Returns:
true if the name matches

accept

public boolean accept(java.io.File pathname)
Specified by:
accept in interface java.io.FileFilter

accept

public boolean accept(java.io.File dir,
                      java.lang.String name)
Specified by:
accept in interface java.io.FilenameFilter

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object