Package uk.ac.starlink.ttools.plottask
Class NamedObjectParameter<T>
- java.lang.Object
-
- uk.ac.starlink.task.Parameter<T>
-
- uk.ac.starlink.ttools.plottask.NamedObjectParameter<T>
-
- Direct Known Subclasses:
ColorParameter
,DashParameter
public abstract class NamedObjectParameter<T> extends uk.ac.starlink.task.Parameter<T>
Parameter subclass for selecting named options. This resemblesChoiceParameter
in that several named choices are available. However, it is also possible to select options which are not in the known option list. For this to work, a pair of methodstoString(java.lang.Object)
andfromString(java.lang.String)
must be implemented as inverses of each other so that a string can be turned into an object. The supplied options do not need to have names which follow this scheme. Note: this class duplicates some of the functionality in other Parameter subclasses. It's here for historical reasons. New code in general ought not to make use of this class.- Since:
- 14 Aug 2008
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Constructor Description NamedObjectParameter(java.lang.String name, java.lang.Class<T> clazz)
Constructs a new parameter with no named options.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addOption(java.lang.String name, T option)
Adds an option with an associated name.abstract T
fromString(java.lang.String name)
Translates a string value for this parameter into the object value which it represents.java.lang.String[]
getNames()
Returns the names of all the named options known for this parameter.java.lang.String
getOptionList()
Returns a formatted XML string giving an unordered list of the options for this parameter.T[]
getOptions()
Returns the option objects for all the named options known for this parameter.java.lang.String
getUsage()
void
setDefaultOption(T option)
Sets the default value of this parameter as an option value object.void
setUsage(java.lang.String usage)
T
stringToObject(uk.ac.starlink.task.Environment env, java.lang.String sval)
java.lang.String
toString(T option)
Translates a possible option value of this parameter into a string which represents it as a string value.-
Methods inherited from class uk.ac.starlink.task.Parameter
clearValue, getDescription, getName, getPosition, getPreferExplicit, getPrompt, getStringDefault, getValueClass, isNullPermitted, objectToString, objectValue, setDescription, setDescription, setName, setNullPermitted, setPosition, setPreferExplicit, setPrompt, setStringDefault, setValue, setValueFromObject, setValueFromString, stringValue, toArray, toString
-
-
-
-
Constructor Detail
-
NamedObjectParameter
public NamedObjectParameter(java.lang.String name, java.lang.Class<T> clazz)
Constructs a new parameter with no named options.- Parameters:
name
- parameter name
-
-
Method Detail
-
addOption
public void addOption(java.lang.String name, T option)
Adds an option with an associated name. This name does not need to betoString(option)
.- Parameters:
name
- option aliasoption
- option value object
-
stringToObject
public T stringToObject(uk.ac.starlink.task.Environment env, java.lang.String sval) throws uk.ac.starlink.task.TaskException
- Specified by:
stringToObject
in classuk.ac.starlink.task.Parameter<T>
- Throws:
uk.ac.starlink.task.TaskException
-
setDefaultOption
public void setDefaultOption(T option)
Sets the default value of this parameter as an option value object.option
must be either one of the values added usingaddOption(java.lang.String, T)
ortoString(java.lang.Object)
must be able to translate it. Or it could be null.- Parameters:
option
- new default value as an object
-
toString
public java.lang.String toString(T option)
Translates a possible option value of this parameter into a string which represents it as a string value.- Parameters:
option
- object value- Returns:
- corresponding string
-
fromString
public abstract T fromString(java.lang.String name)
Translates a string value for this parameter into the object value which it represents. Must return a suitable object value for this parameter, or throw an unchecked exception.The implementation must be such that
fromString(toString(o)).equals(o)
.- Parameters:
name
- option name- Returns:
- corresponding option value
-
getOptionList
public java.lang.String getOptionList()
Returns a formatted XML string giving an unordered list of the options for this parameter. Suitable for insertion into a parameter description. Not enclosed in a <p> element.- Returns:
- option list XML string
-
getNames
public java.lang.String[] getNames()
Returns the names of all the named options known for this parameter.- Returns:
- name list
-
getOptions
public T[] getOptions()
Returns the option objects for all the named options known for this parameter.- Returns:
- object list
-
setUsage
public void setUsage(java.lang.String usage)
- Overrides:
setUsage
in classuk.ac.starlink.task.Parameter<T>
-
getUsage
public java.lang.String getUsage()
- Overrides:
getUsage
in classuk.ac.starlink.task.Parameter<T>
-
-