Class ConfigKey<T>
java.lang.Object
uk.ac.starlink.ttools.plot2.config.ConfigKey<T>
- Direct Known Subclasses:
BooleanConfigKey
,ChoiceConfigKey
,CombinationConfigKey
,DoubleArrayConfigKey
,DoubleConfigKey
,HiddenConfigKey
,IntegerConfigKey
,OptionConfigKey
,StringConfigKey
,SubrangeConfigKey
,TimeConfigKey
,ToggleNullConfigKey
Typed key for use in a ConfigMap.
As well as serving as a key in
ConfigMap
,
this class has methods to allow a command-line or graphical interface
to be constructed for the corresponding values automatically.
Note that this class does not sport the
Equality
annotation. A ConfigKey is normally considered equal only to itself,
not to other similarly-named ConfigKeys.
- Since:
- 22 Feb 2013
- Author:
- Mark Taylor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConverts an object to the value type of this key.Constructs a graphical control with which the user can specify a suitable value for association with this key.Returns the default value associated with this key.getMeta()
Returns metadata about this key.Returns the type of value described by this key.abstract T
stringToValue
(String txt) Decodes a string value to the value type of this key.toString()
abstract String
valueToString
(T value) Reports a value as a string.
-
Constructor Details
-
ConfigKey
Constructor.- Parameters:
meta
- metadata describing this keyclazz
- value type for the values indexed by this keydflt
- default value when key not present in map
-
-
Method Details
-
getMeta
Returns metadata about this key.- Returns:
- metadata
-
getValueClass
Returns the type of value described by this key.- Returns:
- class
-
getDefaultValue
Returns the default value associated with this key. This value may be used when no value is explicitly supplied for this key.- Returns:
- default value
-
cast
Converts an object to the value type of this key.- Parameters:
value
- untyped value- Returns:
- typed value
-
stringToValue
Decodes 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.- Parameters:
txt
- string representation of value- Returns:
- value
- Throws:
ConfigException
-
valueToString
Reports 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.- Parameters:
value
- possible value associated with this key- Returns:
- string representation
-
createSpecifier
Constructs a graphical control with which the user can specify a suitable value for association with this key.- Returns:
- new specifier
-
toString
-