Class SimplePreferenceAccessor<T>
java.lang.Object
org.tquadrat.foundation.config.spi.prefs.PreferenceAccessor<T>
org.tquadrat.foundation.config.spi.prefs.PreferenceAccessorBase<T>
org.tquadrat.foundation.config.spi.prefs.SimplePreferenceAccessor<T>
- Type Parameters:
T- The type of the property value.
- Direct Known Subclasses:
EnumAccessor
@ClassVersion(sourceVersion="$Id: SimplePreferenceAccessor.java 1061 2023-09-25 16:32:43Z tquadrat $")
@API(status=STABLE,
since="0.1.0")
public sealed class SimplePreferenceAccessor<T>
extends PreferenceAccessorBase<T>
permits EnumAccessor<T>
The implementations of
PreferenceAccessor
that uses the given instance of
StringConverter
to translate the values back and forth.- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: SimplePreferenceAccessor.java 1061 2023-09-25 16:32:43Z tquadrat $
- Since:
- 0.1.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.config.spi.prefs.SimplePreferenceAccessor"
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringConverter<T> The implementation ofStringConverterthat is used to convert the preference values back and force. -
Constructor Summary
ConstructorsConstructorDescriptionSimplePreferenceAccessor(String propertyName, Getter<T> getter, Setter<T> setter, StringConverter<T> stringConverter) Creates a newSimplePreferenceAccessorinstance. -
Method Summary
Modifier and TypeMethodDescriptionprotected final TfromString(Preferences node, String s) Converts the given String to an instance of the property type.protected StringConverts the given instance of the property type to a String.Methods inherited from class org.tquadrat.foundation.config.spi.prefs.PreferenceAccessorBase
readPreference, writePreferenceMethods inherited from class org.tquadrat.foundation.config.spi.prefs.PreferenceAccessor
getPropertyName, getter, hasKey, setter
-
Field Details
-
m_StringConverter
The implementation ofStringConverterthat is used to convert the preference values back and force.
-
-
Constructor Details
-
SimplePreferenceAccessor
public SimplePreferenceAccessor(String propertyName, Getter<T> getter, Setter<T> setter, StringConverter<T> stringConverter) Creates a newSimplePreferenceAccessorinstance.- Parameters:
propertyName- The name of the property.getter- The property getter.setter- The property setter.stringConverter- The implementation ofStringConverterthat is used to convert the preference values back and forth.
-
-
Method Details
-
fromString
Converts the given String to an instance of the property type.
This implementation uses
StringConverter.fromString(CharSequence)for the conversion.- Specified by:
fromStringin classPreferenceAccessorBase<T>- Parameters:
node- The "preferences" node that provides the value.s- The String value; can benull.- Returns:
- The propertyType instance; will be
nullif the provided String isnullor cannot be converted to the property type. - Throws:
InvalidPreferenceValueException- The preferences value cannot be translated to the property type.
-
toString
Converts the given instance of the property type to a String.
This implementation uses
StringConverter.toString(Object)for the conversion.- Specified by:
toStringin classPreferenceAccessorBase<T>- Parameters:
t- The property value; can benull.- Returns:
- The String implementation; will be
nullif the provided value isnullor cannot be converted to a String.
-
