ptolemy.domains.ptera.lib
Class ListDirectory.RecursiveFileFilter

java.lang.Object
  extended by ptolemy.domains.ptera.lib.ListDirectory.RecursiveFileFilter
All Implemented Interfaces:
java.io.FilenameFilter
Enclosing class:
ListDirectory

public static class ListDirectory.RecursiveFileFilter
extends java.lang.Object
implements java.io.FilenameFilter

A file name filter that can recursively list files in a directory, including those in subdirectories. When a file name referring to a directory is found, this filter lists the files within that directory again with a new filter in this class.

Since:
Ptolemy II 8.0
Version:
$Id: ListDirectory.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Thomas Huining Feng
Accepted Rating:
Red (tfeng)
Proposed Rating:
Yellow (tfeng)

Nested Class Summary
private static class ListDirectory.RecursiveFileFilter.FileComparator
          A comparator to sort file names.
 
Field Summary
private  java.util.regex.Pattern _ESCAPER
          The pattern for the wildcard conversion.
private  java.util.List<java.io.File> _files
          The list the recently found files and directories.
private  boolean _includeDirectories
          Whether directories should be included.
private  boolean _includeFiles
          Whether files should be included.
private  java.util.regex.Pattern _pattern
          The pattern for the filter.
private  boolean _recursive
          Whether the filter should recursively list subdirectories.
 
Constructor Summary
ListDirectory.RecursiveFileFilter(boolean recursive, boolean includeFiles, boolean includeDirectories)
          Construct a recursive file filter.
ListDirectory.RecursiveFileFilter(boolean recursive, boolean includeFiles, boolean includeDirectories, java.lang.String fileFilter)
          Construct a recursive file filter.
 
Method Summary
private  java.lang.String _escape(java.lang.String string)
          Convert a string with ?
 boolean accept(java.io.File dir, java.lang.String name)
          Return whether the file or directory name in the given directory is accepted.
 java.util.List<java.io.File> getFiles()
          Return the list of all files and directories after the filtering.
static java.io.File[] listFiles(java.io.File directory, boolean recursive, boolean includeFiles, boolean includeDirectories, java.lang.String fileFilter)
          List all the files and directories within the given directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_ESCAPER

private final java.util.regex.Pattern _ESCAPER
The pattern for the wildcard conversion.


_files

private java.util.List<java.io.File> _files
The list the recently found files and directories.


_includeDirectories

private boolean _includeDirectories
Whether directories should be included.


_includeFiles

private boolean _includeFiles
Whether files should be included.


_pattern

private java.util.regex.Pattern _pattern
The pattern for the filter.


_recursive

private boolean _recursive
Whether the filter should recursively list subdirectories.

Constructor Detail

ListDirectory.RecursiveFileFilter

public ListDirectory.RecursiveFileFilter(boolean recursive,
                                         boolean includeFiles,
                                         boolean includeDirectories)
Construct a recursive file filter.

Parameters:
recursive - Whether the filter should recursively list subdirectories.
includeFiles - Whether files should be included.
includeDirectories - Whether directories should be included.

ListDirectory.RecursiveFileFilter

public ListDirectory.RecursiveFileFilter(boolean recursive,
                                         boolean includeFiles,
                                         boolean includeDirectories,
                                         java.lang.String fileFilter)
Construct a recursive file filter.

Parameters:
recursive - Whether the filter should recursively list subdirectories.
includeFiles - Whether files should be included.
includeDirectories - Whether directories should be included.
fileFilter - The filter (with ? and * as wildcards) to filter the accepted file names.
Method Detail

accept

public boolean accept(java.io.File dir,
                      java.lang.String name)
Return whether the file or directory name in the given directory is accepted.

Specified by:
accept in interface java.io.FilenameFilter
Parameters:
dir - The directory.
name - The file or directory name within the given directory.
Returns:
Whether the name is accepted.

getFiles

public java.util.List<java.io.File> getFiles()
Return the list of all files and directories after the filtering. This must be called after all the directories are traversed.

Returns:
The list of files and directories.

listFiles

public static java.io.File[] listFiles(java.io.File directory,
                                       boolean recursive,
                                       boolean includeFiles,
                                       boolean includeDirectories,
                                       java.lang.String fileFilter)
List all the files and directories within the given directory.

Parameters:
directory - The directory.
recursive - Whether the filter should recursively list subdirectories.
includeFiles - Whether files should be included.
includeDirectories - Whether directories should be included.
fileFilter - The filter (with ? and * as wildcards) to filter the accepted file names.
Returns:
The array of all the files and directories found.

_escape

private java.lang.String _escape(java.lang.String string)
Convert a string with ? and * as wildcards into a Java regular expression.

Parameters:
string - The string with file name wildcards.
Returns:
A regular expression.