laser.util.argument
Class ChoiceOption

java.lang.Object
  extended by laser.util.argument.Argument
      extended by laser.util.argument.Option
          extended by laser.util.argument.ChoiceOption
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
IntegerChoiceOption, StringChoiceOption

public abstract class ChoiceOption
extends Option

The ChoiceOption class defines a user-defined option that must be given a value within its list of possible values. A choice option has:

The value and default value should be of the same type.

Author:
Heather M. Conboy (laser-software@cs.umass.edu)
See Also:
Serialized Form

Field Summary
static boolean CHOICE_REPEATABLE_DEFAULT
          The default setting for isRepeatable
 
Fields inherited from class laser.util.argument.Option
DEFAULT_PREFIX, DEFAULT_SUFFIX, NOT_REPEATABLE_CHAR, REPEATABLE_CHAR
 
Fields inherited from class laser.util.argument.Argument
FIRST, HELP_DEFAULT, HELP_PREFIX, REPEATABLE_DEFAULT, TYPE_PREFIX, TYPE_SUFFIX
 
Constructor Summary
protected ChoiceOption(java.lang.String name, java.util.List<?> choices, java.lang.Object defaultValue, java.lang.String helpMessage)
          Creates a new ChoiceOption with the given name and default value.
protected ChoiceOption(java.lang.String name, java.util.List choices, java.lang.Object defaultValue)
          Creates a new ChoiceOption with the given name and default value.
 
Method Summary
 java.util.Iterator getAllChoices()
          Gets the list of possible values of this ChoiceOption.
 java.lang.String getHelp()
          Gets the help for this ChoiceOption.
protected abstract  boolean isValid(java.lang.Object choice)
          Returns whether or not the given choice is valid.
 int numberOfChoices()
          Gets the number of possible values of this ChoiceOption.
protected  void setValue(java.lang.Object value)
          Sets the value of this Argument to the specified value.
 
Methods inherited from class laser.util.argument.Option
getDefault, getDefaultString, getRepeatableChar, getValue, numberOfValues
 
Methods inherited from class laser.util.argument.Argument
check, checkValue, clear, clone, equals, fromStringValue, getHelpMessage, getName, getType, getValue, getValues, initialize, isRepeatable, numberOfActualValues, parseValue, save, toString, toStringValue, toStringValue
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CHOICE_REPEATABLE_DEFAULT

public static final boolean CHOICE_REPEATABLE_DEFAULT
The default setting for isRepeatable

See Also:
Constant Field Values
Constructor Detail

ChoiceOption

protected ChoiceOption(java.lang.String name,
                       java.util.List<?> choices,
                       java.lang.Object defaultValue,
                       java.lang.String helpMessage)
                throws InvalidChoiceException
Creates a new ChoiceOption with the given name and default value. It will be single-valued. The help message will be made available to the user upon request.

Parameters:
name - The name for the option
choices - The possible values for the option
defaultValue - The value of the option if the user doesn't specify a value
helpMessage - The help message to report to the user upon request
Throws:
InvalidChoiceException - if no choices were given or if one of the choices is a duplicate
See Also:
ChoiceOption.CHOICE_REPEATABLE_DEFAULT

ChoiceOption

protected ChoiceOption(java.lang.String name,
                       java.util.List choices,
                       java.lang.Object defaultValue)
                throws InvalidChoiceException
Creates a new ChoiceOption with the given name and default value. It will have the default setting for isRepeatable and helpMessage.

Parameters:
name - The name for the option
choices - The possible values for the option
defaultValue - The value of the option if the user doesn't specify a value
Throws:
InvalidChoiceException - if no choices were given or if one of the choices is a duplicate
See Also:
ChoiceOption.CHOICE_REPEATABLE_DEFAULT, Argument.HELP_DEFAULT
Method Detail

isValid

protected abstract boolean isValid(java.lang.Object choice)
Returns whether or not the given choice is valid.

Returns:
True if the choice is valid and false otherwise

setValue

protected void setValue(java.lang.Object value)
                 throws ArgumentFormatException,
                        ArgumentNotRepeatableException
Sets the value of this Argument to the specified value.

Overrides:
setValue in class Argument
Parameters:
value - The value for this Argument
Throws:
ArgumentNotRepeatableException - if the user attempted to specify multiple values for a single-valued argument
InvalidChoiceException - if the value specified is not one of the possible choices
ArgumentFormatException

numberOfChoices

public int numberOfChoices()
Gets the number of possible values of this ChoiceOption.

Returns:
The number of possible values

getAllChoices

public java.util.Iterator getAllChoices()
Gets the list of possible values of this ChoiceOption.

Returns:
The list of possible values

getHelp

public java.lang.String getHelp()
Gets the help for this ChoiceOption.

Overrides:
getHelp in class Option
Returns:
The help