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

protected abstract class Options.OptionDef extends Object
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
    Modifier and Type
    Field
    Description
    protected String[]
     
    protected int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    OptionDef(String name, int numValuesNeeded, String desc)
    Construct an option that will be required (it must appear on the command line and it does not have a default value.)
    protected
    OptionDef(String name, String[] defaultValues, int numValuesNeeded, String desc)
    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
    OptionDef(String name, String defaultValue, int numValuesNeeded, String desc)
    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 Type
    Method
    Description
    getBigDecimal(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.
    getDate(String[] values, int i)
    Return the ith value for the option as a Date.
    Get the default values for the option.
    Get the name description for the option.
    getInteger(String[] values, int i)
    Return the ith value for the option as an Integer.
    protected String
    Return the ith default value for the option as a String.
    Get the name of the option.
    int
    Return the number of value(s) required by the option.
    getString(String[] values, int i)
    Return the ith value for the option as a 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?
    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
    void
    Method used to validate the values specified on the command line for the option.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • mDefaultValues

      protected String[] mDefaultValues
    • mNumValuesNeeded

      protected int mNumValuesNeeded
  • Constructor Details

    • OptionDef

      protected OptionDef(String name, int numValuesNeeded, String desc)
      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

      protected OptionDef(String name, String defaultValue, int numValuesNeeded, String desc)
      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

      protected OptionDef(String name, String[] defaultValues, int numValuesNeeded, String desc)
      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

      public String getName()
      Get the name of the option. This name will include the leading "-" (i.e. -debug).

      Returns:
      The name of the option.
    • getDesc

      public String getDesc()
      Get the name description for the option.

      Returns:
      The name description for the option.
    • getString

      public String getString(String[] values, int i) throws CommandLineParser.OptionDataException
      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

      public Integer getInteger(String[] values, int i) throws CommandLineParser.OptionDataException
      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

      public boolean getBoolean(String[] values, int i) throws CommandLineParser.OptionDataException
      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

      public Date getDate(String[] values, int i) throws CommandLineParser.OptionDataException
      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

      public String[] getStrings(String[] values) throws CommandLineParser.OptionDataException
      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

      public String[] 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

      public void validateOption(ArrayList values) throws CommandLineParser.OptionDataException
      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 of ALL implies an indefinite number of values are required (or needed) by the option.

      Returns:
      The number of value(s) required by the option.
    • toString

      public String 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

      Overrides:
      toString in class Object
      Returns:
      The string representation of this class.
    • getIthDefaultAsString

      protected String getIthDefaultAsString(int i) throws CommandLineParser.OptionDataException
      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.