Package uk.ac.starlink.task
Class AbstractChoiceParameter<T,C>
java.lang.Object
uk.ac.starlink.task.Parameter<T>
uk.ac.starlink.task.AbstractChoiceParameter<T,C>
- Type Parameters:
T
- parameter result typeC
- option type
- Direct Known Subclasses:
ChoiceParameter
,MultiChoiceParameter
Abstract superclass for parameters that permit choices from a given
list of typed options.
- Since:
- 17 Dec 2021
- Author:
- Mark Taylor
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an option value to this parameter.void
Adds an option value to this parameter with a given name.protected String
choiceToString
(C objVal) Provides a string representation of a given typed value for this parameter.void
Clears the list of known options.Converts an option value object to a string which is used to identify it as a string value of this parameter.Returns the option value associated with a given string by this parameter.String[]
Returns an array of the string values of options accepted by this parameter.C[]
Returns an array of the option objects which may form the values of this parameter.Returns a collection of the option objects which may form the values of this parameter.stringifyOption
(C option) Determines how an option will be represented as a string value of this parameter if no name has explicitly been supplied.protected C
stringToChoice
(String sval) Converts a supplied string to an option value for this parameter, or throws a ParameterValueException if it is not suitable.Methods inherited from class uk.ac.starlink.task.Parameter
clearValue, getDescription, getName, getPosition, getPreferExplicit, getPrompt, getStringDefault, getUsage, getValueClass, isNullPermitted, objectToString, objectValue, setDescription, setDescription, setName, setNullPermitted, setPosition, setPreferExplicit, setPrompt, setStringDefault, setUsage, setValue, setValueFromObject, setValueFromString, stringToObject, stringValue, toArray, toString
-
Constructor Details
-
AbstractChoiceParameter
Constructor.- Parameters:
name
- parameter nameparamClazz
- class of result type for this parameteroptClazz
- class of typed optionoptions
- initial list of typed options available
-
-
Method Details
-
addOption
Adds an option value to this parameter with a given name. The name is the parameter value string used to identify this option.- Parameters:
option
- option objectname
- label for option
-
addOption
Adds an option value to this parameter. The option's name will be determined by this object'sstringifyOption(C)
method.- Parameters:
option
- option object
-
clearOptions
public void clearOptions()Clears the list of known options. -
getOptionNames
Returns an array of the string values of options accepted by this parameter.- Returns:
- permitted options, stringified
-
getOptions
Returns an array of the option objects which may form the values of this parameter.- Returns:
- permitted options
-
getOptionValueList
Returns a collection of the option objects which may form the values of this parameter.- Returns:
- permitted options
-
getName
Converts an option value object to a string which is used to identify it as a string value of this parameter.- Parameters:
option
- option value- Returns:
- string representation
-
stringifyOption
Determines how an option will be represented as a string value of this parameter if no name has explicitly been supplied. The default implementation isString.valueOf(option)
, but this may be overrridden.- Parameters:
option
- option value- Returns:
- string representation of option
-
getOption
Returns the option value associated with a given string by this parameter. Null is returned if none of the options added so far has a name as supplied. Name matching is case-insensitive.- Parameters:
name
- name of option which has been added- Returns:
- corresponding option object
-
stringToChoice
Converts a supplied string to an option value for this parameter, or throws a ParameterValueException if it is not suitable.- Parameters:
sval
- option name- Returns:
- option value, not null
- Throws:
ParameterValueException
- if no such option
-
choiceToString
Provides a string representation of a given typed value for this parameter.- Parameters:
objVal
- typed option- Returns:
- string representation
-