Class MapStore
- All Implemented Interfaces:
PropertySource,PropertyStore
PropertyStore 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 a PropertyLookupResult.present(Optional) result with an empty optional.
This allows you to explicitly override system properties with null values.
Use unset(String) if you want to remove a key entirely (so get(String) returns PropertyLookupResult.missing()).
Example:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
MapStore
public MapStore()
-
-
Method Details
-
get
Returns a setting from this store.Returns
PropertyLookupResult.missing()if the key doesn't exist in the map, or a present result (which may containOptional.empty()if the value was explicitly set tonull ).- Specified by:
getin interfacePropertySource- Parameters:
key- The property name.- Returns:
- The property lookup result.
-
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 return a present result with an empty optional. This allows you to explicitly override system properties with null values.- Specified by:
setin interfacePropertyStore- 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 returnPropertyLookupResult.missing()for all keys.- Specified by:
clearin interfacePropertyStore
-
unset
Removes a setting from this store.After calling this method,
get(String)will returnPropertyLookupResult.missing()for the specified key, indicating that the key doesn't exist in this store.- Specified by:
unsetin interfacePropertyStore- Parameters:
name- The property name to remove.
-