Package com.sodius.oslc.server
Class Settings
- java.lang.Object
-
- com.sodius.oslc.server.Settings
-
public class Settings extends Object
Manages the edition of setting store.Settings can be valid for an entire server (no scope), or can be scoped to a smaller entity, such as a project or a user.
- Since:
- 2.0.0
- See Also:
SettingStore
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
delete(String key)
Deletes a setting.boolean
getBoolean(String key)
Returns existing setting for the given key.boolean
getBoolean(String key, boolean defaultValue)
Returns existing setting for the given key.Optional<String>
getString(String key)
Returns existing setting for the given key.String
getString(String key, String defaultValue)
Returns existing setting for the given key.List<String>
getStrings(String key, char separator)
Returns settings for the given key.static Settings
scope(String scope)
Returns the settings for the given scope.static Settings
scopeOrServer(String scope)
Returns the settings for the given scope.static Settings
server()
Returns the settings scoped to the server.void
setBoolean(String key, boolean value)
Stores a setting.void
setString(String key, String value)
Stores a setting.void
setStrings(String key, List<String> values, char separator)
Stores a list of values.
-
-
-
Method Detail
-
server
public static Settings server()
Returns the settings scoped to the server.- Returns:
- the settings
-
scope
public static Settings scope(String scope)
Returns the settings for the given scope.- Parameters:
scope
- the scope identifier- Returns:
- the settings
- Since:
- 3.5.0
-
scopeOrServer
public static Settings scopeOrServer(String scope)
Returns the settings for the given scope. In case the setting hasn't been defined in the scope, the server setting is returned.- Parameters:
scope
- the scope identifier- Returns:
- the settings
- Since:
- 3.5.0
-
getString
public Optional<String> getString(String key) throws SettingStoreException
Returns existing setting for the given key.- Parameters:
key
- the setting key- Returns:
- the stored setting
- Throws:
SettingStoreException
- if an error occurs while querying the setting
-
getString
public String getString(String key, String defaultValue) throws SettingStoreException
Returns existing setting for the given key. If the setting key doesn't exist or no value is assigned to it, returns the default value.- Parameters:
key
- the setting keydefaultValue
- the default setting value- Returns:
- the stored setting
- Throws:
SettingStoreException
- if an error occurs while querying the setting
-
setString
public void setString(String key, String value) throws SettingStoreException
Stores a setting. If the setting key already exists, the value is updated.- Parameters:
key
- the setting keyvalue
- the setting value- Throws:
SettingStoreException
- if an error occurs while querying the setting
-
getBoolean
public boolean getBoolean(String key) throws SettingStoreException
Returns existing setting for the given key.- Parameters:
key
- the setting key- Returns:
- the stored setting
- Throws:
SettingStoreException
- if an error occurs while querying the setting
-
getBoolean
public boolean getBoolean(String key, boolean defaultValue) throws SettingStoreException
Returns existing setting for the given key. If the setting key doesn't exist, returns the default value.- Parameters:
key
- the setting keydefaultValue
- the default setting value- Returns:
- the stored setting
- Throws:
SettingStoreException
- if an error occurs while querying the setting
-
setBoolean
public void setBoolean(String key, boolean value) throws SettingStoreException
Stores a setting. If the setting key already exists, the value is updated.- Parameters:
key
- the setting keyvalue
- the setting value- Throws:
SettingStoreException
- if an error occurs while querying the setting
-
getStrings
public List<String> getStrings(String key, char separator) throws SettingStoreException
Returns settings for the given key. If the setting key doesn't exist or no value is assigned to it, returns an empty list. Otherwise the stored setting is split using the given separator to return a list of values.- Parameters:
key
- the setting keyseparator
- the separator that was used for storing the list of values- Returns:
- the stored settings
- Throws:
SettingStoreException
- if an error occurs while querying the setting- See Also:
setStrings(String, List, char)
-
setStrings
public void setStrings(String key, List<String> values, char separator) throws SettingStoreException
Stores a list of values. The separator character is used for combining the list of values in a single String to store. If the setting key already exists, the value is updated.- Parameters:
key
- the setting keyvalues
- a list of valuesseparator
- the separator character to use for combining the list of values in a single String to store.- Throws:
SettingStoreException
- if an error occurs while querying the setting- See Also:
getStrings(String, char)
-
delete
public void delete(String key) throws SettingStoreException
Deletes a setting. If the setting does not exists, nothing is done and no error is thrown.- Parameters:
key
- the setting key- Throws:
SettingStoreException
- if an error occurs while querying the setting
-
-