AFLPcore
Class Option

java.lang.Object
  |
  +--AFLPcore.Option

public class Option
extends java.lang.Object

This class provides a way for other class to specify options and parameters. There are three types of options supported by this class. The first is a simply a string indicating that some sort of string should be given as an option. The class that created this option should check to see if the string matches whatever it needs. The second type is a number. The third type is a choice, which consists of a list of possible selections. Some other part of a program may wish to implement a user interface for these different types of options. This way, a program can query a class, get it's options, present the options to the user, and return the users choices to the program. Parameters that the class needs to operate should be marked as required in the constructor.

See Also:
Operation, AFLPgui.OptionsDialog

Field Summary
static int CHOICE
           
static int LABEL
           
static int NUMBER
           
static int STRING
          Constant for denoting option type
 
Constructor Summary
Option(java.lang.String label, int type, boolean required)
           
Option(java.lang.String label, int type, boolean required, int defaultValue)
          Create a new option of the specified type with the specified label.
Option(java.lang.String label, int type, boolean required, java.lang.String defaultString)
          Create a new option of the specified type with the specified label.
Option(java.lang.String label, int type, boolean required, java.lang.String[] values)
          Create a new option of the specified type with the specified label.
Option(java.lang.String label, int type, boolean required, java.lang.String[] values, java.lang.String defaultChoice)
          Create a new option of the specified type with the specified label.
 
Method Summary
 java.lang.String[] getChoices()
          Gives the list of possiblities for a choice option.
 java.lang.String getDefaultChoice()
          Gives the default choice for this option.
 java.lang.String getLabel()
          Gives a label for this option that serves as an identifier for the option.
 double getNumValue()
          Gives the numerical value associated with this option.
 java.lang.String getStringValue()
          Gives the string that represents the value of this option.
 int getType()
          Gives the type of option for this class.
 boolean isRequired()
          Tells whether or not this option is required by an Operation
 boolean isSet()
          Tells whether or not this option has been set to a value.
 void setValue(double setValue)
          Sets the numerical value of this option to the specified value.
 void setValue(java.lang.String setValue)
          Sets the string value of this option to the specified value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STRING

public static final int STRING
Constant for denoting option type

NUMBER

public static final int NUMBER

CHOICE

public static final int CHOICE

LABEL

public static final int LABEL
Constructor Detail

Option

public Option(java.lang.String label,
              int type,
              boolean required)

Option

public Option(java.lang.String label,
              int type,
              boolean required,
              int defaultValue)
Create a new option of the specified type with the specified label. This constructor should be used to create options of the STRING or NUMBER type. The other constructor should be used to create an option of type CHOICE, since it also takes a list of values to choose from.
Parameters:
label - the name of this option
type - one of the type in the class description
required - determines if this "option" is required for the operation or if it is truly optional.
Throws:
java.lang.IllegalArgumentException - occurs when the type is not one known to this class, or if it can only be created with the other constructor because some options require more details than others.

Option

public Option(java.lang.String label,
              int type,
              boolean required,
              java.lang.String defaultString)
Create a new option of the specified type with the specified label. This constructor should be used to create options of the STRING or NUMBER type. The other constructor should be used to create an option of type CHOICE, since it also takes a list of values to choose from.
Parameters:
label - the name of this option
type - one of the type in the class description
required - determines if this "option" is required for the operation or if it is truly optional.
Throws:
java.lang.IllegalArgumentException - occurs when the type is not one known to this class, or if it can only be created with the other constructor because some options require more details than others.

Option

public Option(java.lang.String label,
              int type,
              boolean required,
              java.lang.String[] values)
Create a new option of the specified type with the specified label. This constructor should be used to create options of the CHOICE. The other constructor should be used to create options of other types. This is done because the choice requires an extra bit of information: the possible choices.
Parameters:
label - the name of this option
type - one of the type in the class description
required - determines if this "option" is required for the operation or if it is truly optional.
values - a list of strings representing the possible choices for this option.
Throws:
java.lang.IllegalArgumentException - occurs when the type is not one known to this class that requires the extra String[] parameter. If the type is not one of these, the other constructor should be used and this one will create the error.

Option

public Option(java.lang.String label,
              int type,
              boolean required,
              java.lang.String[] values,
              java.lang.String defaultChoice)
Create a new option of the specified type with the specified label. This constructor should be used to create options of the CHOICE. The other constructor should be used to create options of other types. This is done because the choice requires an extra bit of information: the possible choices.
Parameters:
label - the name of this option
type - one of the type in the class description
required - determines if this "option" is required for the operation or if it is truly optional.
values - a list of strings representing the possible choices for this option.
default - the default choice to be taken for the possilbe list of values. If it is null, no default will be set.
Throws:
java.lang.IllegalArgumentException - occurs when the type is not one known to this class that requires the extra String[] parameter. If the type is not one of these, the other constructor should be used and this one will create the error.
Method Detail

getStringValue

public java.lang.String getStringValue()
Gives the string that represents the value of this option. If the option type does not have a string value, or if the value has not been set, the method will still work, but will simply return an error code.
Returns:
the string, or null if one of the error conditions above occurs.

getNumValue

public double getNumValue()
Gives the numerical value associated with this option.
Returns:
the value, -1 if the value has not been set or if the type of this option does not have a number value.

setValue

public void setValue(java.lang.String setValue)
Sets the string value of this option to the specified value.
Parameters:
setValue - the new value for this option.

setValue

public void setValue(double setValue)
Sets the numerical value of this option to the specified value.
Parameters:
setValue - the new value for this option.

getLabel

public java.lang.String getLabel()
Gives a label for this option that serves as an identifier for the option.
Returns:
a descriptive name for this option.

getType

public int getType()
Gives the type of option for this class. Possible answers include string, number, or choice. These can be identified by comparing the returned value to the constants in this class.
Returns:
the numerical representation of the type of option

isRequired

public boolean isRequired()
Tells whether or not this option is required by an Operation
Returns:
true if it is required.

isSet

public boolean isSet()
Tells whether or not this option has been set to a value.
Returns:
true when it has been set.

getChoices

public java.lang.String[] getChoices()
Gives the list of possiblities for a choice option. For example, consider a "color" option, which could have the choices of : "red," "yellow," "green," and "blue".
Returns:
the choices, null if this option is not of type choice.

getDefaultChoice

public java.lang.String getDefaultChoice()
Gives the default choice for this option. If none is set or if this is not a CHOICE option, it will be null.
Returns:
the default value, or null if not set or not applicable.