jas2.util
Class GetOptions
- java.lang.Object
-
- jas2.util.GetOptions
-
public class GetOptions extends java.lang.ObjectGetOptions 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classGetOptions.BadArgumentsException to throw when an invalid argument is encountered.
-
Constructor Summary
Constructors Constructor and Description GetOptions()Creates an empty GetOptions object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddOption(char shortName, boolean flag)Adds an option to be recognized by parseArgs.voidaddOption(char shortName, boolean flag, java.lang.String comment)Adds an option to be recognized by parseArgs.voidaddOption(java.lang.String longName, boolean flag)Adds an option to be recognized by parseArgs.voidaddOption(java.lang.String longName, boolean flag, java.lang.String comment)Adds an option to be recognized by parseArgs.voidaddOption(java.lang.String longName, char shortName, boolean flag)Adds an option to be recognized by parseArgs.voidaddOption(java.lang.String longName, char shortName, boolean flag, java.lang.String comment)Adds an option to be recognized by parseArgs.voidaddParam(java.lang.String param)Add a parmetervoiddumpOptions()java.lang.StringgetComment(java.lang.String longName)Returns the comment given for the option with the long name longName.java.lang.StringgetOption(java.lang.String longName)Returns the value given for the option with the long name longName.java.lang.StringgetParam(int pNum)Returns a specific parameterjava.lang.String[]getParams()Returns list of parametersbooleanhasOption(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.booleanisLegalOption(java.lang.String longName)Returns true or false depending on if the option with the long name longName is in fact a real option.intnumParams()Returns number of parametersvoidparseArgs(java.lang.String[] argv)Parses the command line arguments.
-
-
-
Constructor Detail
-
GetOptions
public GetOptions()
Creates an empty GetOptions object. Options are added to the object using the addOption method, unlike GetOpt which adds them in the constructor.
-
-
Method Detail
-
addOption
public void addOption(java.lang.String longName, boolean flag)Adds an option to be recognized by parseArgs.- Parameters:
longName- the full name of the optionflag- true if the option is a flag (takes 0 parameters), false otherwise
-
addOption
public void addOption(java.lang.String longName, boolean flag, java.lang.String comment)Adds an option to be recognized by parseArgs.- Parameters:
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 option
-
addOption
public void addOption(char shortName, boolean flag)Adds an option to be recognized by parseArgs.- Parameters:
shortName- the single character name of the optionflag- true if the option is a flag (takes 0 parameters), false otherwise
-
addOption
public void addOption(char shortName, boolean flag, java.lang.String comment)Adds an option to be recognized by parseArgs.- Parameters:
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 option
-
addOption
public void addOption(java.lang.String longName, char shortName, boolean flag)Adds an option to be recognized by parseArgs.- Parameters:
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 otherwise
-
addOption
public void addOption(java.lang.String longName, char shortName, boolean flag, java.lang.String comment)Adds an option to be recognized by parseArgs.- Parameters:
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 option
-
isLegalOption
public 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.- Parameters:
longName- a string describing the option to query for.- Returns:
- true or false.
-
hasOption
public 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.- Parameters:
longName- a string describing the option to query for.- Returns:
- true or false.
-
getOption
public java.lang.String getOption(java.lang.String longName)
Returns the value given for the option with the long name longName. Returns "FLAG" if the option was given but is a flag (takes no arguments).- Parameters:
longName- a string describing the option to query for.- Returns:
- value of option, "FLAG" or null.
-
getComment
public java.lang.String getComment(java.lang.String longName)
Returns the comment given for the option with the long name longName.- Parameters:
longName- a string describing the option to query for.- Returns:
- value of comment or null if no comment exists.
-
dumpOptions
public void dumpOptions()
-
parseArgs
public void parseArgs(java.lang.String[] argv) throws GetOptions.BadArgumentsParses the command line arguments.- Parameters:
argv- the array of arguments (eg. args as given to main())- Throws:
GetOptions.BadArguments- an invalid arg or wrong # of args is encountered
-
getParams
public java.lang.String[] getParams()
Returns list of parameters
-
getParam
public java.lang.String getParam(int pNum)
Returns a specific parameter
-
numParams
public int numParams()
Returns number of parameters
-
addParam
public void addParam(java.lang.String param)
Add a parmeter
-
-
DataMelt 3.0 © DataMelt by jWork.ORG