Package weka.core

Class Settings

  • All Implemented Interfaces:
    java.io.Serializable

    public class Settings
    extends java.lang.Object
    implements java.io.Serializable
    Maintains a collection of settings. Settings are key value pairs which can be grouped together under a given name. All settings managed by an instance of this class are persisted in the central metastore under a given store name. For example, the store name could be the name/ID of an application/ system, and settings could be grouped according to applications, components, panels etc. Default settings (managed by Defaults objects) can be applied to provide initial defaults (or to allow new settings that have yet to be persisted to be added in the future).
    Version:
    $Revision: $
    Author:
    Mark Hall (mhall{[at]}pentaho{[dot]}com)
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Settings.SettingKey
      Class implementing a key for a setting.
    • Constructor Summary

      Constructors 
      Constructor Description
      Settings​(java.lang.String storeName, java.lang.String ID)
      Construct a new Settings object to be stored in the supplied store under the given ID/name
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void applyDefaults​(Defaults defaults)
      Applies a set of default settings.
      java.lang.String getID()
      Get the ID used for these settings
      <T> T getSetting​(java.lang.String ID, java.lang.String key, T defaultValue, Environment env)  
      <T> T getSetting​(java.lang.String ID, Settings.SettingKey key, T defaultValue)
      Get the value of a setting
      <T> T getSetting​(java.lang.String ID, Settings.SettingKey key, T defaultValue, Environment env)
      Get the value of a setting
      java.util.Map<Settings.SettingKey,​java.lang.Object> getSettings​(java.lang.String settingsID)
      Get the settings for a given ID
      java.util.Set<java.lang.String> getSettingsIDs()
      Get a list of settings IDs
      java.lang.String getStoreName()
      Get the store name for these settings
      boolean hasSetting​(java.lang.String settingsID, java.lang.String propName)
      Returns true if a given setting has a value
      boolean hasSettings​(java.lang.String settingsID)
      Returns true if there are settings available for a given ID
      void loadSettings()
      Load the settings with ID m_ID from store m_storeName.
      void saveSettings()
      Save the settings to the metastore
      void setSetting​(java.lang.String ID, Settings.SettingKey propName, java.lang.Object value)
      Set a value for a setting.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Settings

        public Settings​(java.lang.String storeName,
                        java.lang.String ID)
        Construct a new Settings object to be stored in the supplied store under the given ID/name
        Parameters:
        storeName - the name of the store to load/save to in the metastore
        ID - the ID/name to use
    • Method Detail

      • loadSettings

        public void loadSettings()
                          throws java.io.IOException
        Load the settings with ID m_ID from store m_storeName.
        Throws:
        java.io.IOException - if a problem occurs
      • getID

        public java.lang.String getID()
        Get the ID used for these settings
        Returns:
        the ID used
      • getStoreName

        public java.lang.String getStoreName()
        Get the store name for these settings
        Returns:
        the store name
      • applyDefaults

        public void applyDefaults​(Defaults defaults)
        Applies a set of default settings. If the ID of default settings is not known then a new entry is made for it. Otherwise we examine all settings in the default set supplied and add any that we don't have a value for.
        Parameters:
        defaults - the defaults to apply
      • getSettings

        public java.util.Map<Settings.SettingKey,​java.lang.Object> getSettings​(java.lang.String settingsID)
        Get the settings for a given ID
        Parameters:
        settingsID - the ID to get settings for
        Returns:
        a map of settings, or null if the given ID is unknown
      • getSettingsIDs

        public java.util.Set<java.lang.String> getSettingsIDs()
        Get a list of settings IDs
        Returns:
        a list of the settings IDs managed by this settings instance
      • getSetting

        public <T> T getSetting​(java.lang.String ID,
                                java.lang.String key,
                                T defaultValue,
                                Environment env)
      • getSetting

        public <T> T getSetting​(java.lang.String ID,
                                Settings.SettingKey key,
                                T defaultValue)
        Get the value of a setting
        Type Parameters:
        T - the type of the vaue
        Parameters:
        ID - the ID for settings map to lookup (typically the ID of a perspective)
        key - the name of the setting value to lookup
        defaultValue - the default value to use if the setting is not known
        Returns:
        the setting value, or the default value if not found
      • getSetting

        public <T> T getSetting​(java.lang.String ID,
                                Settings.SettingKey key,
                                T defaultValue,
                                Environment env)
        Get the value of a setting
        Type Parameters:
        T - the type of the vaue
        Parameters:
        ID - the ID for settings map to lookup (typically the ID of a perspective)
        key - the name of the setting value to lookup
        defaultValue - the default value to use if the setting is not known
        env - environment variables to use. String setting values will have environment variables replaced automatically
        Returns:
        the setting value, or the default value if not found
      • setSetting

        public void setSetting​(java.lang.String ID,
                               Settings.SettingKey propName,
                               java.lang.Object value)
        Set a value for a setting.
        Parameters:
        ID - the for the settings map to store the setting in (typically the ID of a perspective or application)
        propName - the name of the setting to store
        value - the value of the setting to store
      • hasSettings

        public boolean hasSettings​(java.lang.String settingsID)
        Returns true if there are settings available for a given ID
        Parameters:
        settingsID - the ID to check
        Returns:
        true if there are settings available for that ID
      • hasSetting

        public boolean hasSetting​(java.lang.String settingsID,
                                  java.lang.String propName)
        Returns true if a given setting has a value
        Parameters:
        settingsID - the ID of the settings group
        propName - the actual setting to check for
        Returns:
        true if the setting has a value
      • saveSettings

        public void saveSettings()
                          throws java.io.IOException
        Save the settings to the metastore
        Throws:
        java.io.IOException - if a problem occurs