public class ChoiceParameter<T> extends Parameter<T>
| Constructor and Description |
|---|
ChoiceParameter(java.lang.String name,
java.lang.Class<T> clazz)
Constructs a choice parameter with no initially set options.
|
ChoiceParameter(java.lang.String name,
java.lang.Class<T> clazz,
T[] options)
Constructor.
|
ChoiceParameter(java.lang.String name,
T[] options)
Constructs a choice parameter with an initial option set.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addOption(T option)
Adds an option value to this parameter.
|
void |
addOption(T option,
java.lang.String name)
Adds an option value to this parameter with a given name.
|
void |
clearOptions()
Clears the list of known options.
|
java.lang.String |
getName(T option)
Converts an option value object to a string which is used to identify
it as a string value of this parameter.
|
T |
getOption(java.lang.String name)
Returns the option value associated with a given string by this
parameter.
|
java.lang.String[] |
getOptionNames()
Returns an array of the string values of options accepted by this
parameter.
|
T[] |
getOptions()
Returns an array of the option objects which may form the
values of this parameter.
|
java.util.Collection<T> |
getOptionValueList()
Returns a collection of the option objects which may form the
values of this parameter.
|
java.lang.String |
getUsage()
Returns a usage message.
|
java.lang.String |
objectToString(Environment env,
T objVal)
Takes a typed value of this parameter and formats it as a string
which may be used for presentation to the user.
|
void |
setDefaultOption(T option)
Sets the default value for this parameter to one of the previously
added options.
|
void |
setUsage(java.lang.String usage)
Sets a usage string for this parameter.
|
java.lang.String |
stringifyOption(T option)
Determines how an option will be represented as a string value of
this parameter if no name has explicitly been supplied.
|
T |
stringToObject(Environment env,
java.lang.String sval)
Takes a non-blank string, as supplied by the execution environment,
and turns it into a typed value for this parameter.
|
clearValue, getDescription, getName, getPosition, getPreferExplicit, getPrompt, getStringDefault, getValueClass, isNullPermitted, objectValue, setDescription, setDescription, setName, setNullPermitted, setPosition, setPreferExplicit, setPrompt, setStringDefault, setValue, setValueFromObject, setValueFromString, stringValue, toArray, toStringpublic ChoiceParameter(java.lang.String name,
java.lang.Class<T> clazz,
T[] options)
name - parameter nameclazz - type for values of this parameteroptions - initial array of legal values of this parameterpublic ChoiceParameter(java.lang.String name,
java.lang.Class<T> clazz)
name - parameter nameclazz - type for values of this parameterpublic ChoiceParameter(java.lang.String name,
T[] options)
name - parameter nameoptions - initial array of legal values of this parameterpublic T stringToObject(Environment env, java.lang.String sval) throws TaskException
ParameterIt is an error to supply a null or empty string value.
If this method fails (throws a ParameterValueException)
and if allowClassnameValue is set, then a subsequent
attempt will be made to interpret the stringVal
as the classname of a suitable class with a no-arg constructor.
stringToObject in class Parameter<T>env - execution environment; in most cases this is not required
but for some purposes environment-specific characteristics
may influence the resultsval - non-null, non-empty string valueTaskExceptionpublic java.lang.String objectToString(Environment env, T objVal)
ParameterstringToObject should be possible,
but that is not in general required/guaranteed.
The default implementation uses the value's toString method, but subclasses can override this for smarter behaviour.
objectToString in class Parameter<T>env - execution environmentobjVal - typed parameter valuepublic void addOption(T option, java.lang.String name)
option - option objectname - label for optionpublic void addOption(T option)
stringifyOption(T) method.option - option objectpublic void clearOptions()
public java.lang.String getUsage()
setUsage(java.lang.String), this will return a usage message based on
the list of known options.getUsage in class Parameter<T>Parameter.setUsage(java.lang.String)public void setUsage(java.lang.String usage)
ParameterParameter class uses the string "<value>"
as the default usage string.public void setDefaultOption(T option)
option - default optionpublic java.lang.String[] getOptionNames()
public T[] getOptions()
public java.util.Collection<T> getOptionValueList()
public java.lang.String getName(T option)
option - option valuepublic java.lang.String stringifyOption(T option)
String.valueOf(option),
but this may be overrridden.option - option valuepublic T getOption(java.lang.String name)
name - name of option which has been addedCopyright © 2017 Central Laboratory of the Research Councils. All Rights Reserved.