Class 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 (see 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 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 for setting, 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 by setting)
        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 by setting)
        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 by setting)
        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 if value 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's Setting.fromString(String) method, an error is logged.
        Parameters:
        name - Name of the setting to store
        text - 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 the set(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 the set(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
      • mapUnknownSetting

        public Setting<?> mapUnknownSetting​(Setting<?> setting)