laser.util.argument
Class StringChoiceOption

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

public class StringChoiceOption
extends ChoiceOption

The StringChoiceOption class defines a user-defined choice option of type String.

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

Field Summary
 
Fields inherited from class laser.util.argument.ChoiceOption
CHOICE_REPEATABLE_DEFAULT
 
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
StringChoiceOption(java.lang.String name, java.lang.String[] choices, java.lang.String defaultValue)
          Creates a new StringChoiceOption with the given name and default value.
StringChoiceOption(java.lang.String name, java.lang.String[] choices, java.lang.String defaultValue, java.lang.String helpMessage)
          Creates a new StringChoiceOption with the given name and default value.
 
Method Summary
 void check()
          Checks whether or not the user correctly specified a value for this argument.
 java.lang.Object clone()
          Clones this Object.
protected  java.lang.Object fromStringValue(java.lang.String value)
          Parses a String value into an Object appropriate for the type
protected  java.lang.String getDefaultString()
          Gets the default string which describes the default value of this StringChoiceOption.
 java.lang.String getStringValue()
          Gets the first value of this StringChoiceOption.
 java.lang.String getStringValue(int index)
          Gets the value of this StringChoiceOption at the specified index.
 java.lang.Class getType()
          Gets the type of this Option.
protected  boolean isValid(java.lang.Object choice)
          Returns whether or not the given choice is valid.
 
Methods inherited from class laser.util.argument.ChoiceOption
getAllChoices, getHelp, numberOfChoices, setValue
 
Methods inherited from class laser.util.argument.Option
getDefault, getRepeatableChar, getValue, numberOfValues
 
Methods inherited from class laser.util.argument.Argument
checkValue, clear, equals, getHelpMessage, getName, 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
 

Constructor Detail

StringChoiceOption

public StringChoiceOption(java.lang.String name,
                          java.lang.String[] choices,
                          java.lang.String defaultValue,
                          java.lang.String helpMessage)
                   throws InvalidChoiceException
Creates a new StringChoiceOption with the given name and default value. It will be multi-valued if isRepeatable is true and single-valued otherwise. 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
isRepeatable - If true then this option is multi-valued otherwise it is single-valued
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

StringChoiceOption

public StringChoiceOption(java.lang.String name,
                          java.lang.String[] choices,
                          java.lang.String defaultValue)
                   throws InvalidChoiceException
Creates a new StringChoiceOption 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 boolean isValid(java.lang.Object choice)
Returns whether or not the given choice is valid.

Specified by:
isValid in class ChoiceOption
Returns:
True if the choice is valid and false otherwise

getStringValue

public java.lang.String getStringValue()
Gets the first value of this StringChoiceOption.

Returns:
The first value

getStringValue

public java.lang.String getStringValue(int index)
Gets the value of this StringChoiceOption at the specified index.

NOTE: All options will have at least one value at index Argument.FIRST.

Parameters:
index - The index of the value
Returns:
The string value

fromStringValue

protected java.lang.Object fromStringValue(java.lang.String value)
                                    throws ArgumentFormatException
Parses a String value into an Object appropriate for the type

Specified by:
fromStringValue in class Argument
Parameters:
value - the value
Returns:
the parsed Object
Throws:
ArgumentFormatException - if the value is malformed
See Also:
laser.util.argument.Argument.toStringValue(Object)

getType

public java.lang.Class getType()
Gets the type of this Option.

Specified by:
getType in class Argument
Returns:
The type description

getDefaultString

protected java.lang.String getDefaultString()
Gets the default string which describes the default value of this StringChoiceOption.

Specified by:
getDefaultString in class Option
Returns:
The default string description

check

public void check()
           throws ArgumentFormatException
Checks whether or not the user correctly specified a value for this argument.

Specified by:
check in class Argument
Throws:
ArgumentFormatException

clone

public java.lang.Object clone()
Clones this Object.

Specified by:
clone in class Argument
Returns:
The clone