com.mindprod.filter
Class StartAndEndsWithFilter

java.lang.Object
  extended by com.mindprod.filter.StartAndEndsWithFilter
All Implemented Interfaces:
java.io.FilenameFilter
Direct Known Subclasses:
NoFootFilter

public class StartAndEndsWithFilter
extends java.lang.Object
implements java.io.FilenameFilter

Filter based on startsWith/EndsWith Regex includes/excludes.

To be selected a file must start with one of the include start with strings or end with one of the include end with strings, and it must not start with any of the exclude start with strings or end with any of the exclude exclude end with strings. It need not have both an include start and end string to be included. It need not have both an include start and end string to be excluded.

Rejects all directories.

Since:
2009-05-09
Version:
2.7 2010-11-22 - add optional invert parameter on a number of the filters.
Author:
Roedy Green, Canadian Mind Products

Constructor Summary
StartAndEndsWithFilter()
          constructor.
StartAndEndsWithFilter(boolean invert)
          constructor.
StartAndEndsWithFilter(boolean invert, java.lang.String[] includeStartsWith, java.lang.String[] includeEndsWith, java.util.regex.Pattern[] includeRegexMatch, java.lang.String[] excludeStartsWith, java.lang.String[] excludeEndsWith, java.util.regex.Pattern[] excludeRegexMatch)
          constructor.
StartAndEndsWithFilter(java.lang.String[] includeStartsWith, java.lang.String[] includeEndsWith, java.util.regex.Pattern[] includeRegexMatch, java.lang.String[] excludeStartsWith, java.lang.String[] excludeEndsWith, java.util.regex.Pattern[] excludeRegexMatch)
          constructor.
 
Method Summary
 boolean accept(java.io.File dir, java.lang.String name)
          Select only Files that pass the 4 include/exclude criteria
static void main(java.lang.String[] args)
           
 void setExcludeEndsWith(java.lang.String... excludeEndsWith)
          set strings to exclude when filename ends with these strings.
 void setExcludeRegexMatch(java.util.regex.Pattern... excludeRegexMatch)
          set regex patterns to exclude when filename matches.
 void setExcludeStartsWith(java.lang.String... excludeStartsWith)
          set strings exclude when filename starts with them.
 void setIncludeEndsWith(java.lang.String... includeEndsWith)
          set strings include when filename ends with them.
 void setIncludeRegexMatch(java.util.regex.Pattern... includeRegexMatch)
          set regex patterns to include when filename matches.
 void setIncludeStartsWith(java.lang.String... includeStartsWith)
          set strings include when filename starts with them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StartAndEndsWithFilter

public StartAndEndsWithFilter()
constructor. Fill in criteria later with setters


StartAndEndsWithFilter

public StartAndEndsWithFilter(boolean invert)
constructor. Fill in criteria later with setters

Parameters:
invert - if true, selects files not in the list instead

StartAndEndsWithFilter

public StartAndEndsWithFilter(java.lang.String[] includeStartsWith,
                              java.lang.String[] includeEndsWith,
                              java.util.regex.Pattern[] includeRegexMatch,
                              java.lang.String[] excludeStartsWith,
                              java.lang.String[] excludeEndsWith,
                              java.util.regex.Pattern[] excludeRegexMatch)
constructor. All include/exclude strings must be in lower case. Can use null for unused parms.

Parameters:
includeStartsWith - filename start strings, to include, case insensitive, e.g. new String[ "prod"];
includeEndsWith - filename end strings, to include, case insensitive, e.g. new String[".html", ".txt", .bat" ];
includeRegexMatch - filename regex matches to include
excludeStartsWith - filename start strings, to exclude, case insensitive, e.g. new String["_" ];
excludeEndsWith - filename end strings, to exclude, case insensitive, e.g. new String[".foot.html" ];
excludeRegexMatch - filename regex matches to exclude

StartAndEndsWithFilter

public StartAndEndsWithFilter(boolean invert,
                              java.lang.String[] includeStartsWith,
                              java.lang.String[] includeEndsWith,
                              java.util.regex.Pattern[] includeRegexMatch,
                              java.lang.String[] excludeStartsWith,
                              java.lang.String[] excludeEndsWith,
                              java.util.regex.Pattern[] excludeRegexMatch)
constructor. All include/exclude strings must be in lower case. Can use null for unused parms. * @param invert if true, selects files not in the list instead

Parameters:
includeStartsWith - filename start strings, to include, case insensitive, e.g. new String[ "prod"];
includeEndsWith - filename end strings, to include, case insensitive, e.g. new String[".html", ".txt", .bat" ];
includeRegexMatch - filename regex matches to include
excludeStartsWith - filename start strings, to exclude, case insensitive, e.g. new String["_" ];
excludeEndsWith - filename end strings, to exclude, case insensitive, e.g. new String[".foot.html" ];
excludeRegexMatch - filename regex matches to exclude
Method Detail

accept

public boolean accept(java.io.File dir,
                      java.lang.String name)
Select only Files that pass the 4 include/exclude criteria

Specified by:
accept in interface java.io.FilenameFilter
Parameters:
dir - the directory in which the file was found.
name - the name of the file
Returns:
true if and only if the name should be included in the file list; false otherwise.

setExcludeEndsWith

public void setExcludeEndsWith(java.lang.String... excludeEndsWith)
set strings to exclude when filename ends with these strings. Specify in lower case.

Parameters:
excludeEndsWith - end with strings

setExcludeRegexMatch

public void setExcludeRegexMatch(java.util.regex.Pattern... excludeRegexMatch)
set regex patterns to exclude when filename matches.

Parameters:
excludeRegexMatch - end with strings

setExcludeStartsWith

public void setExcludeStartsWith(java.lang.String... excludeStartsWith)
set strings exclude when filename starts with them. Specify in lower case.

Parameters:
excludeStartsWith - end with strings

setIncludeEndsWith

public void setIncludeEndsWith(java.lang.String... includeEndsWith)
set strings include when filename ends with them. Specify in lower case.

Parameters:
includeEndsWith - end with strings

setIncludeRegexMatch

public void setIncludeRegexMatch(java.util.regex.Pattern... includeRegexMatch)
set regex patterns to include when filename matches.

Parameters:
includeRegexMatch - end with strings

setIncludeStartsWith

public void setIncludeStartsWith(java.lang.String... includeStartsWith)
set strings include when filename starts with them. Specify in lower case.

Parameters:
includeStartsWith - end with strings

main

public static void main(java.lang.String[] args)