com.mindprod.filter
Class FilenameLengthFilter

java.lang.Object
  extended by com.mindprod.filter.FilenameLengthFilter
All Implemented Interfaces:
java.io.FilenameFilter

public final class FilenameLengthFilter
extends java.lang.Object
implements java.io.FilenameFilter

Filter accepting only short or long filenames (not files).

See FileLengthFilter for short or long files. filename used to check the length is File.getName() without path stuff e.g. "thing.html"

Use it like this to get a list of file names shorter than 4 characters.

FilenameFilter f = new FilenameLengthFilter( 4, false ); String[] filenames = new File( "MyDir" ).list( f );

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

Field Summary
static boolean DEBUGGING
          true if debugging.
static boolean LONG_FILENAMES
          convenience constant to remember that true means you want long filenames.
static boolean SHORT_FILENAMES
          convenience constant to help you remember that false means accept short names.
 
Constructor Summary
FilenameLengthFilter(int desiredLength, boolean wantLongNames)
          constructor
 
Method Summary
 boolean accept(java.io.File dir, java.lang.String name)
          Select only files with appropriate length.
static void main(java.lang.String[] args)
          TEST harness
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUGGING

public static final boolean DEBUGGING
true if debugging. Enables debugging harness.

See Also:
Constant Field Values

LONG_FILENAMES

public static final boolean LONG_FILENAMES
convenience constant to remember that true means you want long filenames.

See Also:
Constant Field Values

SHORT_FILENAMES

public static final boolean SHORT_FILENAMES
convenience constant to help you remember that false means accept short names.

See Also:
Constant Field Values
Constructor Detail

FilenameLengthFilter

public FilenameLengthFilter(int desiredLength,
                            boolean wantLongNames)
constructor

Parameters:
desiredLength - The length of filename you want to accept.
wantLongNames - true LONG_FILENAMES if you want filenames longer or equal to the specified length. false SHORT_FILENAMES if you want filenames shorter or equal to the specified length.
Method Detail

accept

public boolean accept(java.io.File dir,
                      java.lang.String name)
Select only files with appropriate length.

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.

main

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

Parameters:
args - not used