Class 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 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 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 key
        defaultValue - 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 key
        value - 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 key
        defaultValue - 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 key
        value - 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 key
        separator - 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 key
        values - a list of values
        separator - 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