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
ConstructorsConstructorDescriptionPreferencesImpl(Node node, @Nullable Principal principal, Map<String, String> initialMap, PreferencesStore store) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the preferences map.booleancontainsKey(String key) getBoolean(String key) booleangetBoolean(String key, boolean fallback) getDecimal(String key) getDecimal(String key, BigDecimal fallback) double<S extends Enum<S>>
S<S extends Enum<S>>
SfloatintlonggetNode()The node identifying this preferences map.<V> V<V> VbooleankeySet()Returns an immutable view of all keys.voidreload()Reloads all values from the storage.booleanremoveValue(String key) voidsave()Saves all changed values to the underlying storage.voidsetAutoFlush(boolean flag) Sets the auto-flush property.booleansetBoolean(String key, boolean bool) booleanbooleansetDecimal(String key, BigDecimal value) booleanbooleanbooleanbooleanbooleanbooleanbooleantoMap()toString()
-
Constructor Details
-
PreferencesImpl
-
-
Method Details
-
setValue
- Specified by:
setValuein interfaceWriteableMap<String>
-
getValue
- Specified by:
getValuein interfaceReadOnlyMap<String>
-
getValue
- Specified by:
getValuein interfaceReadOnlyMap<String>
-
getString
- Specified by:
getStringin interfaceReadOnlyMap<String>
-
getString
- Specified by:
getStringin interfaceReadOnlyMap<String>
-
setString
- Specified by:
setStringin interfaceWriteableMap<String>
-
getInt
- Specified by:
getIntin interfaceReadOnlyMap<String>
-
getInt
- Specified by:
getIntin interfaceReadOnlyMap<String>
-
setInt
- Specified by:
setIntin interfaceWriteableMap<String>
-
setLong
- Specified by:
setLongin interfaceWriteableMap<String>
-
getLong
- Specified by:
getLongin interfaceReadOnlyMap<String>
-
getLong
- Specified by:
getLongin interfaceReadOnlyMap<String>
-
getDouble
- Specified by:
getDoublein interfaceReadOnlyMap<String>
-
getDouble
- Specified by:
getDoublein interfaceReadOnlyMap<String>
-
setDouble
- Specified by:
setDoublein interfaceWriteableMap<String>
-
getFloat
- Specified by:
getFloatin interfaceReadOnlyMap<String>
-
getFloat
- Specified by:
getFloatin interfaceReadOnlyMap<String>
-
setFloat
- Specified by:
setFloatin interfaceWriteableMap<String>
-
getBoolean
- Specified by:
getBooleanin interfaceReadOnlyMap<String>
-
getBoolean
- Specified by:
getBooleanin interfaceReadOnlyMap<String>
-
setBoolean
- Specified by:
setBooleanin interfaceWriteableMap<String>
-
getDecimal
- Specified by:
getDecimalin interfaceReadOnlyMap<String>
-
getDecimal
- Specified by:
getDecimalin interfaceReadOnlyMap<String>
-
setDecimal
- Specified by:
setDecimalin interfaceWriteableMap<String>
-
getEnum
- Specified by:
getEnumin interfaceReadOnlyMap<String>
-
getEnum
- Specified by:
getEnumin interfaceReadOnlyMap<String>
-
setEnum
- Specified by:
setEnumin interfaceWriteableMap<String>
-
setDate
- Specified by:
setDatein interfaceWriteableMap<String>
-
getDate
- Specified by:
getDatein interfaceReadOnlyMap<String>
-
getDate
- Specified by:
getDatein interfaceReadOnlyMap<String>
-
clear
public void clear()Description copied from interface:PreferencesClears the preferences map. If not flushed, any unsaved changes that happened before theclear()are discarded. All changes afterclear()are recorded as usual.- Specified by:
clearin interfacePreferences- Specified by:
clearin interfaceWriteableMap<String>
-
containsKey
- Specified by:
containsKeyin interfaceReadOnlyMap<String>
-
setAutoFlush
public void setAutoFlush(boolean flag) Description copied from interface:PreferencesSets the auto-flush property. If set totrue, each call to a setter will immediately cause saving all changed values.- Specified by:
setAutoFlushin interfacePreferences- Parameters:
flag- autoflush
-
isAutoFlush
public boolean isAutoFlush()- Specified by:
isAutoFlushin interfacePreferences- Returns:
- whether
autoflushmode is enabled or not
-
toMap
- Specified by:
toMapin interfacePreferences
-
save
public void save()Description copied from interface:PreferencesSaves all changed values to the underlying storage.- Specified by:
savein interfacePreferences
-
reload
public void reload()Description copied from interface:PreferencesReloads all values from the storage. Note, that all changed values are lost.- Specified by:
reloadin interfacePreferences
-
removeValue
- Specified by:
removeValuein interfaceWriteableMap<String>
-
keySet
Description copied from interface:ReadOnlyMapReturns an immutable view of all keys.- Specified by:
keySetin interfaceReadOnlyMap<String>
-
getNode
Description copied from interface:PreferencesThe node identifying this preferences map.- Specified by:
getNodein interfacePreferences
-
toString
-