Class MapStore
- All Implemented Interfaces:
SettingSource,SettingStore
SettingStore implementation backed by a thread-safe map.
This class provides a mutable store for settings that can be modified at runtime. It's particularly useful
for creating custom property stores (e.g., Spring properties, configuration files) that can be added to
Settings as sources.
Thread Safety:
This class is thread-safe. The internal map is lazily initialized using AtomicReference and
ConcurrentHashMap for thread-safe operations.
Null Value Handling:
Setting a value to get(String)
will return unset(String) if you want to remove a key entirely (so get(String) returns
Example:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
MapStore
public MapStore()
-
-
Method Details
-
get
Returns a setting from this store.Returns
null if the key doesn't exist in the map, or the stored value (which may beOptional.empty() if the value was explicitly set tonull ).- Specified by:
getin interfaceSettingSource- Parameters:
key- The property name.- Returns:
- The property value,
null if the key doesn't exist, orOptional.empty() if the key exists but has a null value.
-
set
Sets a setting in this store.The internal map is lazily initialized on the first call to this method. Setting a value to
null storesOptional.empty() in the map, which meansget(String)will returnOptional.empty() (notnull ). This allows you to explicitly override system properties with null values.- Specified by:
setin interfaceSettingStore- Parameters:
key- The property name.value- The property value, ornull to set an empty override.
-
clear
Clears all entries from this store.After calling this method, all keys will be removed from the map, and
get(String)will returnnull for all keys.- Specified by:
clearin interfaceSettingStore
-
unset
Removes a setting from this store.After calling this method,
get(String)will returnnull for the specified key, indicating that the key doesn't exist in this store (as opposed to returningOptional.empty() , which would indicate the key exists but has a null value).- Specified by:
unsetin interfaceSettingStore- Parameters:
name- The property name to remove.
-