Package cdc.prefs
Class AbstractPreference<T>
java.lang.Object
cdc.prefs.AbstractPreference<T>
- Type Parameters:
T- The preference type.
- All Implemented Interfaces:
Preference<T>
- Direct Known Subclasses:
BooleanPreference,BytePreference,DatePreference,DoublePreference,EnumPreference,FilePreference,FloatPreference,IntegerPreference,LongPreference,ShortPreference,StringPreference
Base implementation of Preference.
- Author:
- Damien Carbonne
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractPreference(Class<T> valueClass, Preferences node, String key, T def) Creates an abstract preference.protectedAbstractPreference(Class<T> valueClass, Preferences node, String key, T def, Function<T, String> toString, Function<String, T> fromString) Creates an abstract preference. -
Method Summary
Modifier and TypeMethodDescriptionprotected TfromString(String s) Converts a string to a value usingfomString.final TReturns the value associated to this (node, key).final Tfinal StringgetKey()final PreferencesgetNode()final voidPuts a value into this (node, key).protected StringConverts a value to a string usingtoString.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface cdc.prefs.Preference
get
-
Constructor Details
-
AbstractPreference
protected AbstractPreference(Class<T> valueClass, Preferences node, String key, T def, Function<T, String> toString, Function<String, T> fromString) Creates an abstract preference.If
toStringisnull,toStringmust be implemented.
IffromStringisnull,fromStringmust be implemented.- Parameters:
valueClass- The value class.node- The Preferences node.key- The preferences key.def- The default value.toString- Optional function used to convert from value type to string.fromString- Optional function used to convert from string to value type.
-
AbstractPreference
Creates an abstract preference.toStringandfromStringmust be implemented.- Parameters:
valueClass- The value class.node- The Preferences node.key- The preferences key.def- The default value.
-
-
Method Details
-
toString
Converts a value to a string usingtoString.If
valueisnull, returns"".- Parameters:
value- The value.- Returns:
- The corresponding string.
- Throws:
IllegalStateException- WhentoStringisnullandvalueis notnull.
-
fromString
Converts a string to a value usingfomString.If
sisnullor empty, returnsnull.- Parameters:
s- The string.- Returns:
- The corresponding value.
- Throws:
IllegalStateException- WhenfromStringisnullandsis neithernullor empty.
-
getValueClass
- Specified by:
getValueClassin interfacePreference<T>- Returns:
- The value class.
-
getNode
- Specified by:
getNodein interfacePreference<T>- Returns:
- The associated node.
-
getKey
- Specified by:
getKeyin interfacePreference<T>- Returns:
- The associated key.
-
getDefaultValue
- Specified by:
getDefaultValuein interfacePreference<T>- Returns:
- The default value.
-
put
Description copied from interface:PreferencePuts a value into this (node, key).- Specified by:
putin interfacePreference<T>- Parameters:
value- The value.
-
get
Description copied from interface:PreferenceReturns the value associated to this (node, key).- Specified by:
getin interfacePreference<T>- Parameters:
def- The default value to return when there is no associated value or value processing raises an exception- Returns:
- The associated value or
def.
-