Package ch.tocco.nice2.usersettings.impl
Class PreferencesImpl
java.lang.Object
ch.tocco.nice2.usersettings.impl.PreferencesImpl
- All Implemented Interfaces:
ReadOnlyMap<String>
,WriteableMap<String>
,Preferences
This implemenation maintains two maps: one is the initial map as specified when creating this object, the other
one collects all changes tracked by the various setters. On each call of
save()
the two maps are merged
and the new values are written to the backend.
This class is not thread safe. Use an instance from
PreferencesFactory.getPreferences(Node)
in each thread.-
Field Summary
Fields inherited from interface ch.tocco.nice2.usersettings.api.Preferences
KEY_FIELD, PATH_FIELD, PREF_ENTITY, VALUE_FIELD
-
Constructor Summary
ConstructorDescriptionPreferencesImpl
(Node node, @Nullable Principal principal, Map<String, String> initialMap, PreferencesStore store) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the preferences map.boolean
containsKey
(String key) getBoolean
(String key) boolean
getBoolean
(String key, boolean fallback) getDecimal
(String key) getDecimal
(String key, BigDecimal fallback) double
<S extends Enum<S>>
S<S extends Enum<S>>
Sfloat
int
long
getNode()
The node identifying this preferences map.<V> V
<V> V
boolean
keySet()
Returns an immutable view of all keys.void
reload()
Reloads all values from the storage.boolean
removeValue
(String key) void
save()
Saves all changed values to the underlying storage.void
setAutoFlush
(boolean flag) Sets the auto-flush property.boolean
setBoolean
(String key, boolean bool) boolean
boolean
setDecimal
(String key, BigDecimal value) boolean
boolean
boolean
boolean
boolean
boolean
boolean
toMap()
toString()
-
Constructor Details
-
PreferencesImpl
-
-
Method Details
-
setValue
- Specified by:
setValue
in interfaceWriteableMap<String>
-
getValue
- Specified by:
getValue
in interfaceReadOnlyMap<String>
-
getValue
- Specified by:
getValue
in interfaceReadOnlyMap<String>
-
getString
- Specified by:
getString
in interfaceReadOnlyMap<String>
-
getString
- Specified by:
getString
in interfaceReadOnlyMap<String>
-
setString
- Specified by:
setString
in interfaceWriteableMap<String>
-
getInt
- Specified by:
getInt
in interfaceReadOnlyMap<String>
-
getInt
- Specified by:
getInt
in interfaceReadOnlyMap<String>
-
setInt
- Specified by:
setInt
in interfaceWriteableMap<String>
-
setLong
- Specified by:
setLong
in interfaceWriteableMap<String>
-
getLong
- Specified by:
getLong
in interfaceReadOnlyMap<String>
-
getLong
- Specified by:
getLong
in interfaceReadOnlyMap<String>
-
getDouble
- Specified by:
getDouble
in interfaceReadOnlyMap<String>
-
getDouble
- Specified by:
getDouble
in interfaceReadOnlyMap<String>
-
setDouble
- Specified by:
setDouble
in interfaceWriteableMap<String>
-
getFloat
- Specified by:
getFloat
in interfaceReadOnlyMap<String>
-
getFloat
- Specified by:
getFloat
in interfaceReadOnlyMap<String>
-
setFloat
- Specified by:
setFloat
in interfaceWriteableMap<String>
-
getBoolean
- Specified by:
getBoolean
in interfaceReadOnlyMap<String>
-
getBoolean
- Specified by:
getBoolean
in interfaceReadOnlyMap<String>
-
setBoolean
- Specified by:
setBoolean
in interfaceWriteableMap<String>
-
getDecimal
- Specified by:
getDecimal
in interfaceReadOnlyMap<String>
-
getDecimal
- Specified by:
getDecimal
in interfaceReadOnlyMap<String>
-
setDecimal
- Specified by:
setDecimal
in interfaceWriteableMap<String>
-
getEnum
- Specified by:
getEnum
in interfaceReadOnlyMap<String>
-
getEnum
- Specified by:
getEnum
in interfaceReadOnlyMap<String>
-
setEnum
- Specified by:
setEnum
in interfaceWriteableMap<String>
-
setDate
- Specified by:
setDate
in interfaceWriteableMap<String>
-
getDate
- Specified by:
getDate
in interfaceReadOnlyMap<String>
-
getDate
- Specified by:
getDate
in interfaceReadOnlyMap<String>
-
clear
public void clear()Description copied from interface:Preferences
Clears the preferences map. If not flushed, any unsaved changes that happened before theclear()
are discarded. All changes afterclear()
are recorded as usual.- Specified by:
clear
in interfacePreferences
- Specified by:
clear
in interfaceWriteableMap<String>
-
containsKey
- Specified by:
containsKey
in interfaceReadOnlyMap<String>
-
setAutoFlush
public void setAutoFlush(boolean flag) Description copied from interface:Preferences
Sets the auto-flush property. If set totrue
, each call to a setter will immediately cause saving all changed values.- Specified by:
setAutoFlush
in interfacePreferences
- Parameters:
flag
- autoflush
-
isAutoFlush
public boolean isAutoFlush()- Specified by:
isAutoFlush
in interfacePreferences
- Returns:
- whether
autoflush
mode is enabled or not
-
toMap
- Specified by:
toMap
in interfacePreferences
-
save
public void save()Description copied from interface:Preferences
Saves all changed values to the underlying storage.- Specified by:
save
in interfacePreferences
-
reload
public void reload()Description copied from interface:Preferences
Reloads all values from the storage. Note, that all changed values are lost.- Specified by:
reload
in interfacePreferences
-
removeValue
- Specified by:
removeValue
in interfaceWriteableMap<String>
-
keySet
Description copied from interface:ReadOnlyMap
Returns an immutable view of all keys.- Specified by:
keySet
in interfaceReadOnlyMap<String>
-
getNode
Description copied from interface:Preferences
The node identifying this preferences map.- Specified by:
getNode
in interfacePreferences
-
toString
-