## mars.util
Class FilenameFinder

    java.lang.Object
      mars.util.FilenameFinder

    public class FilenameFinder

extends Object

Utility class to perform necessary file-related search operations. One is to find file names in JAR file, another is to find names of files in given directory of normal file system.

Author:
  Pete Sanderson

Field Summary
`static String` `MATCH_ALL_EXTENSIONS`

Constructor Summary
`FilenameFinder()`

Method Summary
`static boolean` `fileExtensionMatch(String name, String extension)` Determine if given filename ends with given extension.
`static String` `getExtension(File file)` Get the filename extension of the specified File.
`static FileFilter` `getFileFilter(ArrayList extensions, String description)` Get a FileFilter that will filter files based on the given list of filename extensions.
`static FileFilter` `getFileFilter(ArrayList extensions, String description, boolean acceptDirectories)` Get a FileFilter that will filter files based on the given list of filename extensions.
`static FileFilter` `getFileFilter(String extension, String description)` Get a FileFilter that will filter files based on the given filename extension.
`static FileFilter` `getFileFilter(String extension, String description, boolean acceptDirectories)` Get a FileFilter that will filter files based on the given filename extension.
`static ArrayList` `getFilenameList(ArrayList nameList, ArrayList fileExtensions)` Return list of file names.
`static ArrayList` `getFilenameList(ArrayList nameList, String fileExtension)` Return list of file names.
`static ArrayList` `getFilenameList(ClassLoader classLoader, String directoryPath, ArrayList fileExtensions)` Locate files and return list of file names.
`static ArrayList` `getFilenameList(ClassLoader classLoader, String directoryPath, String fileExtension)` Locate files and return list of file names.
`static ArrayList` `getFilenameList(String directoryPath, ArrayList fileExtensions)` Locate files and return list of file names.
`static ArrayList` `getFilenameList(String directoryPath, String fileExtension)` Locate files and return list of file names.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### MATCH_ALL_EXTENSIONS

    public static String MATCH_ALL_EXTENSIONS

Constructor Detail

### FilenameFinder

    public FilenameFinder()

Method Detail

### getFilenameList

    public static ArrayList getFilenameList(ClassLoader classLoader,
                                            String directoryPath,
                                            String fileExtension)

  Locate files and return list of file names. Given a known relative directory path, it will locate it and build list of all names of files in that directory having the given file extension. If the "known file path" doesn't work because MARS is running from an executable JAR file, it will locate the directory in the JAR file and proceed from there. NOTE: since this uses the class loader to get the resource, the directory path needs to be relative to classpath, not absolute. To work with an arbitrary file system, use the other version of this overloaded method. Will NOT match directories that happen to have the desired extension.

  Parameters:
    `classLoader` - class loader to use
    `directoryPath` - Search will be confined to this directory. Use "/" as separator but do NOT include starting or ending "/" (e.g. mars/tools)
    `fileExtension` - Only files with this extension will be added to the list. Do NOT include the "." in extension.
  Returns:
    array list of matching file names as Strings. If none, list is empty.

### getFilenameList

    public static ArrayList getFilenameList(ClassLoader classLoader,
                                            String directoryPath,
                                            ArrayList fileExtensions)

  Locate files and return list of file names. Given a known relative directory path, it will locate it and build list of all names of files in that directory having the given file extension. If the "known file path" doesn't work because MARS is running from an executable JAR file, it will locate the directory in the JAR file and proceed from there. NOTE: since this uses the class loader to get the resource, the directory path needs to be relative to classpath, not absolute. To work with an arbitrary file system, use the other version of this overloaded method.

  Parameters:
    `classLoader` - class loader to use
    `directoryPath` - Search will be confined to this directory. Use "/" as separator but do NOT include starting or ending "/" (e.g. mars/tools)
    `fileExtensions` - ArrayList of Strings containing file extensions. Only files with an extension in this list will be added to the list. Do NOT include the ".", eg "class" not ".class". If Arraylist or extension null or empty, all files are added.
  Returns:
    array list of matching file names as Strings. If none, list is empty.

### getFilenameList

    public static ArrayList getFilenameList(String directoryPath,
                                            String fileExtension)

  Locate files and return list of file names. Given a known directory path, it will locate it and build list of all names of files in that directory having the given file extension. If file extenion is null or empty, all filenames are returned. Returned list contains absolute filename paths.

  Parameters:
    `directoryPath` - Search will be confined to this directory.
    `fileExtension` - Only files with this extension will be added to the list. Do NOT include "." in extension. If null or empty string, all files are added.
  Returns:
    array list of matching file names (absolute path). If none, list is empty.

### getFilenameList

    public static ArrayList getFilenameList(String directoryPath,
                                            ArrayList fileExtensions)

  Locate files and return list of file names. Given a known directory path, it will locate it and build list of all names of files in that directory having the given file extension. If file extenion is null or empty, all filenames are returned. Returned list contains absolute filename paths.

  Parameters:
    `directoryPath` - Search will be confined to this directory.
    `fileExtensions` - ArrayList of Strings containing file extensions. Only files with an extension in this list will be added to the list. Do NOT include the "." in extensions. If Arraylist or extension null or empty, all files are added.
  Returns:
    array list of matching file names (absolute path). If none, list is empty.

### getFilenameList

    public static ArrayList getFilenameList(ArrayList nameList,
                                            String fileExtension)

  Return list of file names. Given a list of file names, it will return the list of all having the given file extension. If file extenion is null or empty, all filenames are returned. Returned list contains absolute filename paths.

  Parameters:
    `nameList` - ArrayList of String containing file names.
    `fileExtension` - Only files with this extension will be added to the list. If null or empty string, all files are added. Do NOT include "." in extension.
  Returns:
    array list of matching file names (absolute path). If none, list is empty.

### getFilenameList

    public static ArrayList getFilenameList(ArrayList nameList,
                                            ArrayList fileExtensions)

  Return list of file names. Given a list of file names, it will return the list of all having the given file extension. If file extenion is null or empty, all filenames are returned. Returned list contains absolute filename paths.

  Parameters:
    `nameList` - ArrayList of String containing file names.
    `fileExtensions` - ArrayList of Strings containing file extensions. Only files with an extension in this list will be added to the list. Do NOT include the "." in extensions. If Arraylist or extension null or empty, all files are added.
  Returns:
    array list of matching file names (absolute path). If none, list is empty.

### getExtension

    public static String getExtension(File file)

  Get the filename extension of the specified File.

  Parameters:
    `file` - the File object representing the file of interest
  Returns:
    The filename extension (everything that follows last '.' in filename) or null if none.

### getFileFilter

    public static FileFilter getFileFilter(ArrayList extensions,
                                           String description,
                                           boolean acceptDirectories)

  Get a FileFilter that will filter files based on the given list of filename extensions.

  Parameters:
    `extensions` - ArrayList of Strings, each string is acceptable filename extension.
    `description` - String containing description to be added in parentheses after list of extensions.
    `acceptDirectories` - boolean value true if directories are accepted by the filter, false otherwise.
  Returns:
    a FileFilter object that accepts files with given extensions, and directories if so indicated.

### getFileFilter

    public static FileFilter getFileFilter(ArrayList extensions,
                                           String description)

  Get a FileFilter that will filter files based on the given list of filename extensions. All directories are accepted by the filter.

  Parameters:
    `extensions` - ArrayList of Strings, each string is acceptable filename extension
    `description` - String containing description to be added in parentheses after list of extensions.
  Returns:
    a FileFilter object that accepts files with given extensions, and directories if so indicated.

### getFileFilter

    public static FileFilter getFileFilter(String extension,
                                           String description,
                                           boolean acceptDirectories)

  Get a FileFilter that will filter files based on the given filename extension.

  Parameters:
    `extension` - String containing acceptable filename extension.
    `description` - String containing description to be added in parentheses after list of extensions.
    `acceptDirectories` - boolean value true if directories are accepted by the filter, false otherwise.
  Returns:
    a FileFilter object that accepts files with given extensions, and directories if so indicated.

### getFileFilter

    public static FileFilter getFileFilter(String extension,
                                           String description)

  Get a FileFilter that will filter files based on the given filename extension. All directories are accepted by the filter.

  Parameters:
    `extension` - String containing acceptable filename extension
    `description` - String containing description to be added in parentheses after list of extensions.
  Returns:
    a FileFilter object that accepts files with given extensions, and directories if so indicated.

### fileExtensionMatch

    public static boolean fileExtensionMatch(String name,
                                             String extension)

  Determine if given filename ends with given extension.

  Parameters:
    `name` - A String containing the file name
    `extension` - A String containing the file extension. Leading period is optional.
  Returns:
    Returns true if filename ends with given extension, false otherwise.