Package com.impossibl.postgres.system
Class Settings
- java.lang.Object
-
- com.impossibl.postgres.system.Settings
-
public class Settings extends Object
Managed bag of textual settings that can be read & updated. The values for each setting are stored as text and converted as necessary. The settings are store via their primary name (seeSetting
). When setting values via one of a setting's alternate names the name is mapped back to the primary before storage. Values set via raw text are validated usingSetting.fromString(String)
before they are stored; an error is logged if validation fails. If a setting name is unrecognized, a warning is logged before storing the value.
-
-
Constructor Summary
Constructors Constructor Description Settings()
Creates a bag of settings that recognizes any global setting defined.Settings(Setting.Group... groups)
Creates a bag of settings that recognizes only settings from the provided groups.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Settings
addMappedUnknownSetting(Setting<?> setting, Properties to)
Properties
asProperties()
Settings
duplicateKnowing(Setting.Group... groups)
Duplicates the bag of settings knowing settings from the specified groupsSettings
duplicateKnowingAll()
Duplicates the bag of settings knowing settings from all groupsboolean
enabled(Setting<Boolean> setting)
Retrieve a boolean value from a setting.<T> T
get(Setting<T> setting)
Retrieve a value for a setting.<T> T
getStored(Setting<T> setting)
Retrieve a stored value for the setting, returning null if no value was explicitly stored.String
getText(Setting<?> setting)
Retrieve text value for a setting.boolean
hasStoredValue(Setting<?> setting)
Check if settings has a stored value stored for the setting.Set<Setting<?>>
knownSet()
Retrieves a list of settings known to this instance.Setting<?>
mapUnknownSetting(Setting<?> setting)
<T> void
set(Setting<T> setting, T value)
Sets a value for the specified setting.void
set(String name, String text)
Sets a setting via string name and text value.void
setAll(Settings settings)
Transfers all settings from given settings bag into this instance.void
setAll(Map<String,String> settings)
Sets all values from the given map as settings via theset(String, String)
method.void
setAll(Properties properties)
Sets all properties from the given instance as settings via theset(String, String)
method.void
setText(Setting<?> setting, String value)
Set text value for a setting.void
unset(Setting<?> setting)
Remove any stored value associated with the setting.void
unset(String name)
Remove any stored value associated with the named setting.void
unsetAll(Collection<Setting<?>> settings)
Remove any stored value associated with any of the settings.
-
-
-
Constructor Detail
-
Settings
public Settings()
Creates a bag of settings that recognizes any global setting defined.
-
Settings
public Settings(Setting.Group... groups)
Creates a bag of settings that recognizes only settings from the provided groups.- Parameters:
groups
- Array of setting groups to recognize.
-
-
Method Detail
-
duplicateKnowingAll
public Settings duplicateKnowingAll()
Duplicates the bag of settings knowing settings from all groups- Returns:
- Duplicate settings bag
-
duplicateKnowing
public Settings duplicateKnowing(Setting.Group... groups)
Duplicates the bag of settings knowing settings from the specified groups- Parameters:
groups
- Groups which the new settings bag will consider known.- Returns:
- Duplicate settings bag
-
knownSet
public Set<Setting<?>> knownSet()
Retrieves a list of settings known to this instance.- Returns:
- Set of all known settings.
-
hasStoredValue
public boolean hasStoredValue(Setting<?> setting)
Check if settings has a stored value stored for the setting.- Parameters:
setting
- Setting to check status of.- Returns:
true
if a value is stored forsetting
,false
otherwise.
-
enabled
public boolean enabled(Setting<Boolean> setting)
Retrieve a boolean value from a setting. If no value is set, and there is no default for the setting, false is returned.- Parameters:
setting
- Boolean setting to retrieve.- Returns:
- Stored value of setting, its default value or
false
.
-
get
public <T> T get(Setting<T> setting)
Retrieve a value for a setting.- Type Parameters:
T
- Type of the setting (inferred bysetting
)- Parameters:
setting
- Setting to retrieve.- Returns:
- Stored value of setting or its default value.
-
getStored
public <T> T getStored(Setting<T> setting)
Retrieve a stored value for the setting, returning null if no value was explicitly stored.- Type Parameters:
T
- Type of the setting (inferred bysetting
)- Parameters:
setting
- Setting to retrieve.- Returns:
- Stored value of setting or null.
-
getText
public String getText(Setting<?> setting)
Retrieve text value for a setting.- Parameters:
setting
- Setting to retrieve.- Returns:
- Stored text value of setting or its default value.
-
set
public <T> void set(Setting<T> setting, T value)
Sets a value for the specified setting.- Type Parameters:
T
- Type of the setting (inferred bysetting
)- Parameters:
setting
- Setting to set.value
- Native value to set.
-
setText
public void setText(Setting<?> setting, String value)
Set text value for a setting. An error is logged ifvalue
cannot be validated.- Parameters:
setting
- Setting to set.value
- Text value for setting.
-
set
public void set(String name, String text)
Sets a setting via string name and text value. If the name provided does not match any defined primary or alternate name know to the settings bag a warning is logged. If the value provided does cannot be validated via the associated setting'sSetting.fromString(String)
method, an error is logged.- Parameters:
name
- Name of the setting to storetext
- Value of the store to store
-
setAll
public void setAll(Settings settings)
Transfers all settings from given settings bag into this instance.- Parameters:
settings
- Settings to transfer
-
setAll
public void setAll(Map<String,String> settings)
Sets all values from the given map as settings via theset(String, String)
method. All validation applies.- Parameters:
settings
- Map of values to apply as settings.
-
setAll
public void setAll(Properties properties)
Sets all properties from the given instance as settings via theset(String, String)
method. All validation applies.- Parameters:
properties
- Properties to apply as settings.
-
unset
public void unset(Setting<?> setting)
Remove any stored value associated with the setting.- Parameters:
setting
- Setting to remove
-
unset
public void unset(String name)
Remove any stored value associated with the named setting.- Parameters:
name
- Name of setting to remove
-
unsetAll
public void unsetAll(Collection<Setting<?>> settings)
Remove any stored value associated with any of the settings.- Parameters:
settings
- Settings to remove
-
asProperties
public Properties asProperties()
-
addMappedUnknownSetting
public Settings addMappedUnknownSetting(Setting<?> setting, Properties to)
-
-