public class Settings extends Object
Setting
). 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 using Setting.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 and 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.
|
Modifier and Type | Method and Description |
---|---|
Settings |
addMappedUnknownSetting(Setting<?> setting,
Properties to) |
Properties |
asProperties() |
Settings |
duplicateKnowing(Setting.Group... groups)
Duplicates the bag of settings knowing settings from the specified groups
|
Settings |
duplicateKnowingAll()
Duplicates the bag of settings knowing settings from all groups
|
boolean |
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(Map<String,String> settings)
Sets all values from the given map as settings via
the
set(String, String) method. |
void |
setAll(Properties properties)
Sets all properties from the given instance as settings via
the
set(String, String) method. |
void |
setAll(Settings settings)
Transfers all settings from given settings bag
into this instance.
|
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.
|
public Settings()
public Settings(Setting.Group... groups)
groups
- Array of setting groups to recognize.public Settings duplicateKnowingAll()
public Settings duplicateKnowing(Setting.Group... groups)
groups
- Groups which the new settings bag will consider known.public Set<Setting<?>> knownSet()
public boolean hasStoredValue(Setting<?> setting)
setting
- Setting to check status of.true
if a value is stored for setting
, false
otherwise.public boolean enabled(Setting<Boolean> setting)
setting
- Boolean setting to retrieve.false
.public <T> T get(Setting<T> setting)
T
- Type of the setting (inferred by setting
)setting
- Setting to retrieve.public <T> T getStored(Setting<T> setting)
T
- Type of the setting (inferred by setting
)setting
- Setting to retrieve.public String getText(Setting<?> setting)
setting
- Setting to retrieve.public <T> void set(Setting<T> setting, T value)
T
- Type of the setting (inferred by setting
)setting
- Setting to set.value
- Native value to set.public void setText(Setting<?> setting, String value)
value
cannot
be validated.setting
- Setting to set.value
- Text value for setting.public void set(String name, String text)
Setting.fromString(String)
method, an error is
logged.name
- Name of the setting to storetext
- Value of the store to storepublic void setAll(Settings settings)
settings
- Settings to transferpublic void setAll(Map<String,String> settings)
set(String, String)
method. All validation
applies.settings
- Map of values to apply as settings.public void setAll(Properties properties)
set(String, String)
method. All validation
applies.properties
- Properties to apply as settings.public void unset(Setting<?> setting)
setting
- Setting to removepublic void unset(String name)
name
- Name of setting to removepublic void unsetAll(Collection<Setting<?>> settings)
settings
- Settings to removepublic Properties asProperties()
public Settings addMappedUnknownSetting(Setting<?> setting, Properties to)