mark.core.args
Class ArgUtil

java.lang.Object
  |
  +--mark.core.args.ArgUtil

public class ArgUtil
extends java.lang.Object

Provides a number of routines that help manage specific arguments in an ArgHelper.


Constructor Summary
ArgUtil()
           
 
Method Summary
static java.lang.String addPrefix(java.lang.String prefix, java.lang.String arg)
          Constructs a new string from the given arg string as follows: capitalizes the second character and inserts the prefix string between the first and second characters.
static java.lang.String[] addPrefix(java.lang.String prefix, java.lang.String[] args)
          Replaces each arg string in the given array with a new arg string constructed by calling addPrefix (String, String).
static java.io.FileFilter extractFileFilter(ArgHelper args, boolean required, java.lang.String prefix)
          Extracts a FileFilter argument from the given ArgHelper.
static java.util.ArrayList extractFileSet(ArgHelper args, boolean required, java.lang.String prefix, java.io.FileFilter ff)
          Extracts a file set argument from the given ArgHelper.
static void extractFilesFromFile(ArgHelper args, boolean required, java.lang.String match, java.util.Collection c)
          Extracts a filename from the given ArgHelper and fills the given collection with files corresponding to the paths in the file.
static void extractWordsFromFile(ArgHelper args, boolean required, java.lang.String match, boolean lowerCase, java.util.Collection c)
          Extracts a filename from the given ArgHelper and fills the given collection with the words in the file.
static java.lang.String fileFilterUsage(java.lang.String prefix)
          Returns the usage string for a FileFilter argument.
static java.lang.String fileSetUsage(java.lang.String prefix)
          Returns the usage string for a file set argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArgUtil

public ArgUtil()
Method Detail

addPrefix

public static java.lang.String addPrefix(java.lang.String prefix,
                                         java.lang.String arg)
Constructs a new string from the given arg string as follows: capitalizes the second character and inserts the prefix string between the first and second characters. Examples: train, -filter -> -trainFilter test, -dataSet -> -testDataSet

Parameters:
prefix - the prefix string.
arg - the arg string.

addPrefix

public static java.lang.String[] addPrefix(java.lang.String prefix,
                                           java.lang.String[] args)
Replaces each arg string in the given array with a new arg string constructed by calling addPrefix (String, String). Returns the modified array.

Parameters:
prefix - the prefix string.
args - the arg strings.

extractWordsFromFile

public static void extractWordsFromFile(ArgHelper args,
                                        boolean required,
                                        java.lang.String match,
                                        boolean lowerCase,
                                        java.util.Collection c)
                                 throws java.lang.Exception
Extracts a filename from the given ArgHelper and fills the given collection with the words in the file.

Parameters:
args - the ArgHelper.
required - whether to throw an exception if the argument is not in args.
match - the argument that precededs the filename in args.
lowerCase - whether to convert the words to lower-case before returning them.
c - the collection.
java.lang.Exception

extractFilesFromFile

public static void extractFilesFromFile(ArgHelper args,
                                        boolean required,
                                        java.lang.String match,
                                        java.util.Collection c)
                                 throws java.lang.Exception
Extracts a filename from the given ArgHelper and fills the given collection with files corresponding to the paths in the file.

Parameters:
args - the ArgHelper.
required - whether to throw an exception if the argument is not in args.
match - the argument that precededs the filename in args.
c - the collection.
java.lang.Exception

fileFilterUsage

public static java.lang.String fileFilterUsage(java.lang.String prefix)
Returns the usage string for a FileFilter argument.

Parameters:
prefix - the name of the arguement (if more than one of same type).
Returns:
the usage string.

extractFileFilter

public static java.io.FileFilter extractFileFilter(ArgHelper args,
                                                   boolean required,
                                                   java.lang.String prefix)
                                            throws java.lang.Exception
Extracts a FileFilter argument from the given ArgHelper.

Parameters:
args - the ArgHelper.
required - whether the argument is required.
prefix - the name of the argument (if more than one of same type).
Returns:
the FileFilter or null if there is none.
Throws:
java.lang.Exception - if there is no filter and required.

fileSetUsage

public static java.lang.String fileSetUsage(java.lang.String prefix)
Returns the usage string for a file set argument.

Parameters:
prefix - the name of the arguement (if more than one of same type).
Returns:
the usage string.

extractFileSet

public static java.util.ArrayList extractFileSet(ArgHelper args,
                                                 boolean required,
                                                 java.lang.String prefix,
                                                 java.io.FileFilter ff)
                                          throws java.lang.Exception
Extracts a file set argument from the given ArgHelper. The method will match exactly one of the following: (1) -files (e.g. -files /usr/mark/dir,/usr/mark/file.txt) (2) -Files (3) -from (e.g. -from listOfFiles.txt) (4) -From If the parameter prefix is null, then the method looks for forms (1) and (3) in the given ArgHelper. Otherwise, it looks for forms (2) and (4). If it finds form (1) or (2), then it obtains paths from the command line. If it finds form (3) or (4), then it obtains paths from the given file. Either way, it processes each path obtained recursively to generate a complete set of potential paths. Each potential path is then sent to the given file filter to determine whether it is included in the set. If the client specified no file filter, then the method includes all potential paths.

Parameters:
args - the ArgHelper.
required - whether the argument is required.
prefix - the name of the argument (if more than one of same type).
ff - the file filter.
Returns:
an ArrayList with Files in it (an empty one if there are none)
Throws:
java.lang.Exception - if there is no file set and required.