io.args
Class ArgumentParser

java.lang.Object
  extended byio.args.ArgumentParser

public class ArgumentParser
extends java.lang.Object


Field Summary
 java.util.HashMap available
           
 java.util.HashMap definitions
           
 java.lang.String helpText
           
 java.lang.String progname
           
 
Constructor Summary
ArgumentParser()
           
 
Method Summary
protected  void checkHelp(java.util.HashMap av)
          if the arguments contain the help keyword, print a usage text and exit.
private  java.util.HashMap checkInputFile(java.util.HashMap av)
          if the arguments contain the f keyword, read the corresponding input file.
protected  void checkValues()
          assert that all the supplied arguments conform to the argument value definitions.
protected  java.util.HashMap compareArgs(java.util.HashMap availableArgs)
          compare the supplied arguments with the defined arguments
private  java.util.HashMap getArgs(java.lang.String[] argv)
          read the argument data from various sources (argument vector, or file).
 java.util.HashMap parse(java.lang.String[] argv)
          parses an array of strings, doing cross checks against defined arguments and defined argument values.
 void put(ArgumentDescription a)
          Add another argument description
static java.util.ArrayList readinputfile(java.lang.String file)
          slurp contents of an input file, stripping comments
 java.lang.String usage()
          supply a usage string detailing program name, program usage and defined arguments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

progname

public java.lang.String progname

helpText

public java.lang.String helpText

definitions

public java.util.HashMap definitions

available

public java.util.HashMap available
Constructor Detail

ArgumentParser

public ArgumentParser()
Method Detail

parse

public java.util.HashMap parse(java.lang.String[] argv)
parses an array of strings, doing cross checks against defined arguments and defined argument values. if the arguments don't conflict with any definitions, return a HashMap or argument names -> argument values.

Parameters:
argv -
Returns:
the argument tree

put

public void put(ArgumentDescription a)
         throws java.io.IOException
Add another argument description

Parameters:
a - ArgumentDescription
Throws:
java.io.IOException

usage

public java.lang.String usage()
supply a usage string detailing program name, program usage and defined arguments.

Returns:
a usage string

getArgs

private java.util.HashMap getArgs(java.lang.String[] argv)
                           throws java.io.IOException
read the argument data from various sources (argument vector, or file). handle special arguments such as @help.

Parameters:
argv -
Returns:
return the completed dat
Throws:
java.io.IOException

checkInputFile

private java.util.HashMap checkInputFile(java.util.HashMap av)
                                  throws java.io.IOException
if the arguments contain the f keyword, read the corresponding input file.

Parameters:
av -
Returns:
the tokens on the input file
Throws:
java.io.IOException

readinputfile

public static java.util.ArrayList readinputfile(java.lang.String file)
                                         throws java.io.IOException
slurp contents of an input file, stripping comments

Parameters:
file -
Returns:
the file contents
Throws:
java.io.IOException

checkHelp

protected void checkHelp(java.util.HashMap av)
                  throws java.io.IOException
if the arguments contain the help keyword, print a usage text and exit.

Parameters:
av -
Throws:
java.io.IOException

compareArgs

protected java.util.HashMap compareArgs(java.util.HashMap availableArgs)
                                 throws java.io.IOException
compare the supplied arguments with the defined arguments

Parameters:
availableArgs -
Returns:
the scrubbed arguments
Throws:
java.io.IOException

checkValues

protected void checkValues()
                    throws java.io.IOException
assert that all the supplied arguments conform to the argument value definitions.

Throws:
java.io.IOException