Package com.portal.common
Class Options.OptionDef
java.lang.Object
com.portal.common.Options.OptionDef
- Direct Known Subclasses:
Options.DateOptionDef
,Options.DecimalOptionDef
,Options.FlagOptionDef
,Options.IntOptionDef
,Options.StringOptionDef
- Enclosing class:
Options
Abstract class used to define an option. The defnition includes
state for the option (option name, default vlaue (if one exists),
number of values used by the option, etc.), an overridable
validation method, and a base implementation for data access methods.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Construct an option that will be required (it must appear on the command line and it does not have a default value.)protected
Construct an option that will be not be required to appear on the command line and there will be multiple default values if it does not appear on the command line.protected
Construct an option that will be not be required to appear on the command line and there will be a default value if it does not appear on the command line. -
Method Summary
Modifier and TypeMethodDescriptiongetBigDecimal
(String[] values, int i) Return the ith value for the option as a BigDecimal.boolean
getBoolean
(String[] values, int i) Return the ith value for the option as a boolean.Return the ith value for the option as a Date.String[]
Get the default values for the option.getDesc()
Get the name description for the option.getInteger
(String[] values, int i) Return the ith value for the option as an Integer.protected String
getIthDefaultAsString
(int i) Return the ith default value for the option as a String.getName()
Get the name of the option.int
Return the number of value(s) required by the option.Return the ith value for the option as a String.String[]
getStrings
(String[] values) Return the values for the option as an array of strings.boolean
Is the option required to appear on the command line?toString()
Convert this class to a string that will contain the following: Name of the option class Name of the option Values needed by the option The default values for the option The is required flagvoid
validateOption
(ArrayList values) Method used to validate the values specified on the command line for the option.
-
Field Details
-
mDefaultValues
-
mNumValuesNeeded
protected int mNumValuesNeeded
-
-
Constructor Details
-
OptionDef
Construct an option that will be required (it must appear on the command line and it does not have a default value.)- Parameters:
name
- The name of the option. The name should include the leading "-" (i.e. "-verbose").numValuesNeeded
- The number of value(s) required by the option.desc
- The description of the option.
-
OptionDef
Construct an option that will be not be required to appear on the command line and there will be a default value if it does not appear on the command line.- Parameters:
name
- The name of the option. The name should include the leading "-" (i.e. "-verbose").numValuesNeeded
- The number of value(s) required by the option.desc
- The description of the option.The
- default value for the option if the option does not appear on the command line.
-
OptionDef
Construct an option that will be not be required to appear on the command line and there will be multiple default values if it does not appear on the command line.- Parameters:
name
- The name of the option. The name should include the leading "-" (i.e. "-verbose").numValuesNeeded
- The number of value(s) required by the option.desc
- The description of the option.The
- default values for the option if the option does not appear on the command line.
-
-
Method Details
-
getName
Get the name of the option. This name will include the leading "-" (i.e. -debug).- Returns:
- The name of the option.
-
getDesc
Get the name description for the option.- Returns:
- The name description for the option.
-
getString
Return the ith value for the option as a String. If there is no ith value but the option definition has an ith default value then return the ith default value, otherwise throw an exception.- Parameters:
values
- The array of values retrieved from the command line for the option.i
- The index of the value to return. The index is zero relative (i.e. a value of zero implies the first value).- Returns:
- the ith value or ith default value for the option as a String.
- Throws:
CommandLineParser.OptionDataException
- There is no ith value or ith default value for the option.
-
getInteger
Return the ith value for the option as an Integer. If there is no ith value but the option definition has an ith default value then return the ith default value, otherwise throw an exception.- Parameters:
values
- The array of values retrieved from the command line for the option.i
- The index of the value to return. The index is zero relative (i.e. a value of zero implies the first value).- Returns:
- the ith value or ith default value for the option as an Integer.
- Throws:
CommandLineParser.OptionDataException
- There is no ith value or ith default value for the option.
-
getBigDecimal
public BigDecimal getBigDecimal(String[] values, int i) throws CommandLineParser.OptionDataException Return the ith value for the option as a BigDecimal. If there is no ith value but the option definition has an ith default value then return the ith default value, otherwise throw an exception.- Parameters:
values
- The array of values retrieved from the command line for the option.i
- The index of the value to return. The index is zero relative (i.e. a value of zero implies the first value).- Returns:
- the ith value or ith default value for the option as a BigDecimal.
- Throws:
CommandLineParser.OptionDataException
- There is no ith value or ith default value for the option.
-
getBoolean
Return the ith value for the option as a boolean. If there is no ith value but the option definition has an ith default value then return the ith default value, otherwise throw an exception.- Parameters:
values
- The array of values retrieved from the command line for the option.i
- The index of the value to return. The index is zero relative (i.e. a value of zero implies the first value).- Returns:
- The ith value or ith default value for the option as a boolean.
- Throws:
CommandLineParser.OptionDataException
- There is no ith value or ith default value for the option.
-
getDate
Return the ith value for the option as a Date. If there is no ith value but the option definition has an ith default value then return the ith default value, otherwise throw an exception.- Parameters:
values
- The array of values retrieved from the command line for the option.i
- The index of the value to return. The index is zero relative (i.e. a value of zero implies the first value).- Returns:
- the ith value or ith default value for the option as a Date.
- Throws:
CommandLineParser.OptionDataException
- There is no ith value or ith default value for the option.
-
getStrings
Return the values for the option as an array of strings. If there are no values (the option does not appear on the command line) but the option definition has default values then return the default values.- Parameters:
values
- The array of values retrieved from the command line for the option.- Returns:
- the values or default values for the option as an array of strings.
- Throws:
CommandLineParser.OptionDataException
- There are no values or default values for the option.
-
getDefaultValues
Get the default values for the option.- Returns:
- The array of default values for the options. If there are no options an empty array will be returned.
-
isRequiredOption
public boolean isRequiredOption()Is the option required to appear on the command line?- Returns:
- true if the option required to appear on the command line, otherwise return false.
-
validateOption
Method used to validate the values specified on the command line for the option. The default implementation validates the number of values required by the option.- Parameters:
values
- An array that contains the values that were specified on the command line for the option. If no values were specified then the array will be empty.- Throws:
CommandLineParser.OptionDataException
- The value(s) specified for the option are invalid.
-
getNumValuesNeeded
public int getNumValuesNeeded()Return the number of value(s) required by the option. A value ofALL
implies an indefinite number of values are required (or needed) by the option.- Returns:
- The number of value(s) required by the option.
-
toString
Convert this class to a string that will contain the following:- Name of the option class
- Name of the option
- Values needed by the option
- The default values for the option
- The is required flag
-
getIthDefaultAsString
Return the ith default value for the option as a String. If there is no ith default value then throw an exception.- Parameters:
i
- The index of the default value to return. The index is zero relative (i.e. a value of zero implies the first value).- Returns:
- the ith default value for the option as a String.
- Throws:
CommandLineParser.OptionDataException
- There is no ith default value for the option.
-