Class ChoiceConfigKey<T>
java.lang.Object
uk.ac.starlink.ttools.plot2.config.ConfigKey<T>
uk.ac.starlink.ttools.plot2.config.ChoiceConfigKey<T>
- Direct Known Subclasses:
ColorConfigKey, DashConfigKey, ShaderConfigKey
ConfigKey that allows named choices from a given list,
and optionally provides other ways of specifying values
from string descriptions.
- Since:
- 10 Sep 2014
- Author:
- Mark Taylor
-
Constructor Summary
ConstructorsConstructorDescriptionChoiceConfigKey(ConfigMeta meta, Class<T> clazz, T dflt, boolean nullPermitted) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an option to the permitted list.abstract TdecodeString(String sval) Takes a string, and attempts to turn it into an object which may be a value for this key.Returns a mutable map giving the currently available known options and their string values.abstract StringstringifyValue(T value) Takes an object which may be a value of this key, and attempts to turn it into a string for reporting purposes.stringToValue(String sval) Decodes a string value to the value type of this key.valueToString(T value) Reports a value as a string.Methods inherited from class ConfigKey
cast, createSpecifier, getDefaultValue, getMeta, getValueClass, toString
-
Constructor Details
-
ChoiceConfigKey
Constructor.- Parameters:
meta- metadataclazz- value classdflt- default valuenullPermitted- true iff null is a permitted value
-
-
Method Details
-
addOption
Adds an option to the permitted list. Its name is obtained using thestringifyValue(T)method, which must return a non-null value.For more flexibility, you can manipulate the return value of
getOptionMap()directly.- Parameters:
option- option to add
-
getOptionMap
-
decodeString
Takes a string, and attempts to turn it into an object which may be a value for this key. If the string is not of a recognised form, null is returned.This method should be the opposite of
stringifyValue(T), but does not need to be consistent withstringToValueorvalueToString.- Parameters:
sval- string representation- Returns:
- typed object represented by sval, or null
-
stringifyValue
Takes an object which may be a value of this key, and attempts to turn it into a string for reporting purposes.This method should if possible be the opposite of
decodeString(String), but does not need to be consistent withstringToValueorvalueToString. If no round-trippable value is available, null should be returned.- Parameters:
value- typed object- Returns:
- string representing object, or null
-
stringToValue
Description copied from class:ConfigKeyDecodes a string value to the value type of this key. An empty string should be interpreted as a null value, but this may cause an exception if null is not a permissible value for this key.- Specified by:
stringToValuein classConfigKey<T>- Parameters:
sval- string representation of value- Returns:
- value
- Throws:
ConfigException
-
valueToString
Description copied from class:ConfigKeyReports a value as a string. If at all possible the roundtripping should be possible, sostringToValue(valueToString(v)).equals(v). A null value, if permitted, should be represented as an empty string.- Specified by:
valueToStringin classConfigKey<T>- Parameters:
value- possible value associated with this key- Returns:
- string representation
-