|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jas.util.GetOptions
GetOptions is used to help parse command line arguments. It is loosely based on Paul Raines' GetOpt module with modifications to handle multiple classes wanting access to the same arguments. The main design difference is that instead of doing all the work in the constructor we do it with addOption() and parseArgs(). Furthermore, the Hashtables are different, etc.
Inner Class Summary | |
static class |
GetOptions.BadArguments
Exception to throw when an invalid argument is encountered. |
Field Summary | |
protected java.util.Hashtable |
longToComment
Maps a long option to its comment. |
protected java.util.Hashtable |
longToIsFlagMap
Maps a long option to whether it is a flag (takes no parameters). |
protected java.util.Hashtable |
longToOptionsMap
The storage of options. |
protected java.lang.String[] |
params
The list of arguments that followed the options. |
protected java.util.Vector |
pVector
Vector used to dynamically build options. |
protected java.util.Hashtable |
shortToLongMap
Maps a short option to its equivalent long one. |
Constructor Summary | |
GetOptions()
Creates an empty GetOptions object. |
Method Summary | |
void |
addOption(char shortName,
boolean flag)
Adds an option to be recognized by parseArgs. |
void |
addOption(char shortName,
boolean flag,
java.lang.String comment)
Adds an option to be recognized by parseArgs. |
void |
addOption(java.lang.String longName,
boolean flag)
Adds an option to be recognized by parseArgs. |
void |
addOption(java.lang.String longName,
boolean flag,
java.lang.String comment)
Adds an option to be recognized by parseArgs. |
void |
addOption(java.lang.String longName,
char shortName,
boolean flag)
Adds an option to be recognized by parseArgs. |
void |
addOption(java.lang.String longName,
char shortName,
boolean flag,
java.lang.String comment)
Adds an option to be recognized by parseArgs. |
void |
addParam(java.lang.String param)
Add a parmeter |
void |
dumpOptions()
|
java.lang.String |
getComment(java.lang.String longName)
Returns the comment given for the option with the long name longName. |
java.lang.String |
getOption(java.lang.String longName)
Returns the value given for the option with the long name longName. |
java.lang.String |
getParam(int pNum)
Returns a specific parameter |
java.lang.String[] |
getParams()
Returns list of parameters |
boolean |
hasOption(java.lang.String longName)
Returns true or false depending on if the option with the long name longName was given in either the short (if one exists) or the long form. |
boolean |
isLegalOption(java.lang.String longName)
Returns true or false depending on if the option with the long name longName is in fact a real option. |
int |
numParams()
Returns number of parameters |
void |
parseArgs(java.lang.String[] argv)
Parses the command line arguments. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.String[] params
protected java.util.Vector pVector
protected java.util.Hashtable shortToLongMap
protected java.util.Hashtable longToIsFlagMap
protected java.util.Hashtable longToComment
protected java.util.Hashtable longToOptionsMap
Constructor Detail |
public GetOptions()
Method Detail |
public void addOption(java.lang.String longName, boolean flag)
longName
- the full name of the optionflag
- true if the option is a flag (takes 0 parameters), false otherwisepublic void addOption(java.lang.String longName, boolean flag, java.lang.String comment)
longName
- the full name of the optionflag
- true if the option is a flag (takes 0 parameters), false otherwisecomment
- description of the arguments to the optionpublic void addOption(char shortName, boolean flag)
shortName
- the single character name of the optionflag
- true if the option is a flag (takes 0 parameters), false otherwisepublic void addOption(char shortName, boolean flag, java.lang.String comment)
shortName
- the single character name of the optionflag
- true if the option is a flag (takes 0 parameters), false otherwisecomment
- description of the arguments to the optionpublic void addOption(java.lang.String longName, char shortName, boolean flag)
longName
- the full name of the optionshortName
- the single character name of the optionflag
- true if the option is a flag (takes 0 parameters), false otherwisepublic void addOption(java.lang.String longName, char shortName, boolean flag, java.lang.String comment)
longName
- the full name of the optionshortName
- the single character name of the optionflag
- true if the option is a flag (takes 0 parameters), false otherwisecomment
- description of the arguments to the optionpublic boolean isLegalOption(java.lang.String longName)
longName
- a string describing the option to query for.public boolean hasOption(java.lang.String longName)
longName
- a string describing the option to query for.public java.lang.String getOption(java.lang.String longName)
longName
- a string describing the option to query for.public java.lang.String getComment(java.lang.String longName)
longName
- a string describing the option to query for.public void dumpOptions()
public void parseArgs(java.lang.String[] argv) throws GetOptions.BadArguments
argv
- the array of arguments (eg. args as given to main())GetOptions.BadArguments
- an invalid arg or wrong # of args is encounteredpublic java.lang.String[] getParams()
public java.lang.String getParam(int pNum)
public int numParams()
public void addParam(java.lang.String param)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |