Class AbstractPreferences

java.lang.Object
org.openstreetmap.josm.spi.preferences.AbstractPreferences
All Implemented Interfaces:
IPreferences
Direct Known Subclasses:
MemoryPreferences, Preferences

public abstract class AbstractPreferences extends Object implements IPreferences
Abstract implementation of the IPreferences interface.
Since:
12847
  • Field Details

  • Constructor Details

  • Method Details

    • get

      public String get(String key, String def)
      Description copied from interface: IPreferences
      Get settings value for a certain key and provide a default value.
      Specified by:
      get in interface IPreferences
      Parameters:
      key - the identifier for the setting
      def - the default value. For each call of get() with a given key, the default value must be the same. def may be null.
      Returns:
      the corresponding value if the property has been set before, def otherwise
    • put

      public boolean put(String key, String value)
      Description copied from interface: IPreferences
      Set a value for a certain setting.
      Specified by:
      put in interface IPreferences
      Parameters:
      key - the unique identifier for the setting
      value - the value of the setting. Can be null or "" which both removes the key-value entry.
      Returns:
      true, if something has changed (i.e. value is different than before)
    • getBoolean

      public boolean getBoolean(String key, boolean def)
      Description copied from interface: IPreferences
      Gets a boolean preference
      Specified by:
      getBoolean in interface IPreferences
      Parameters:
      key - The preference key
      def - The default value to use
      Returns:
      The boolean, false if it could not be parsed, the default value if it is unset
    • putBoolean

      public boolean putBoolean(String key, boolean value)
      Description copied from interface: IPreferences
      Set a boolean value for a certain setting.
      Specified by:
      putBoolean in interface IPreferences
      Parameters:
      key - the unique identifier for the setting
      value - The new value
      Returns:
      true, if something has changed (i.e. value is different than before)
    • getInt

      public int getInt(String key, int def)
      Description copied from interface: IPreferences
      Gets an integer preference
      Specified by:
      getInt in interface IPreferences
      Parameters:
      key - The preference key
      def - The default value to use
      Returns:
      The integer
    • putInt

      public boolean putInt(String key, int value)
      Description copied from interface: IPreferences
      Set an integer value for a certain setting.
      Specified by:
      putInt in interface IPreferences
      Parameters:
      key - the unique identifier for the setting
      value - The new value
      Returns:
      true, if something has changed (i.e. value is different than before)
    • getLong

      public long getLong(String key, long def)
      Description copied from interface: IPreferences
      Gets a long preference
      Specified by:
      getLong in interface IPreferences
      Parameters:
      key - The preference key
      def - The default value to use
      Returns:
      The long value or the default value if it could not be parsed
    • putLong

      public boolean putLong(String key, long value)
      Description copied from interface: IPreferences
      Set a long value for a certain setting.
      Specified by:
      putLong in interface IPreferences
      Parameters:
      key - the unique identifier for the setting
      value - The new value
      Returns:
      true, if something has changed (i.e. value is different than before)
    • getDouble

      public double getDouble(String key, double def)
      Description copied from interface: IPreferences
      Gets a double preference
      Specified by:
      getDouble in interface IPreferences
      Parameters:
      key - The preference key
      def - The default value to use
      Returns:
      The double value or the default value if it could not be parsed
    • putDouble

      public boolean putDouble(String key, double value)
      Description copied from interface: IPreferences
      Set a boolean value for a certain setting.
      Specified by:
      putDouble in interface IPreferences
      Parameters:
      key - the unique identifier for the setting
      value - The new value
      Returns:
      true, if something has changed (i.e. value is different than before)
    • getList

      public List<String> getList(String key, List<String> def)
      Description copied from interface: IPreferences
      Get a list of values for a certain key
      Specified by:
      getList in interface IPreferences
      Parameters:
      key - the identifier for the setting
      def - the default value.
      Returns:
      the corresponding value if the property has been set before, def otherwise
    • putList

      public boolean putList(String key, List<String> value)
      Description copied from interface: IPreferences
      Set a list of values for a certain key.
      Specified by:
      putList in interface IPreferences
      Parameters:
      key - the identifier for the setting
      value - The new value
      Returns:
      true, if something has changed (i.e. value is different than before)
    • getListOfLists

      public List<List<String>> getListOfLists(String key, List<List<String>> def)
      Description copied from interface: IPreferences
      Get an array of values (list of lists) for a certain key
      Specified by:
      getListOfLists in interface IPreferences
      Parameters:
      key - the identifier for the setting
      def - the default value.
      Returns:
      the corresponding value if the property has been set before, def otherwise
    • putListOfLists

      public boolean putListOfLists(String key, List<List<String>> value)
      Description copied from interface: IPreferences
      Set an array of values (list of lists) for a certain key.
      Specified by:
      putListOfLists in interface IPreferences
      Parameters:
      key - the identifier for the setting
      value - the new value
      Returns:
      true, if something has changed (i.e. value is different than before)
    • getListOfMaps

      Description copied from interface: IPreferences
      Gets a list of key/value maps.
      Specified by:
      getListOfMaps in interface IPreferences
      Parameters:
      key - the key to search at
      def - the default value to use
      Returns:
      the corresponding value if the property has been set before, def otherwise
    • putListOfMaps

      public boolean putListOfMaps(String key, List<Map<String,String>> value)
      Description copied from interface: IPreferences
      Set an a list of key/value maps.
      Specified by:
      putListOfMaps in interface IPreferences
      Parameters:
      key - the key to store the list in
      value - a list of key/value maps
      Returns:
      true if the value was changed
    • getAllSettings

      public abstract Map<String,Setting<?>> getAllSettings()
      Gets a map of all settings that are currently stored
      Returns:
      The settings
    • putSetting

      public abstract boolean putSetting(String key, Setting<?> setting)
      Set a value for a certain setting. The changed setting is saved to the preference file immediately. Due to caching mechanisms on modern operating systems and hardware, this shouldn't be a performance problem.
      Parameters:
      key - the unique identifier for the setting
      setting - the value of the setting. In case it is null, the key-value entry will be removed.
      Returns:
      true, if something has changed (i.e. value is different than before)
    • getSetting

      public abstract <T extends Setting<?>> T getSetting(String key, T def, Class<T> klass)
      Get settings value for a certain key and provide default a value.
      Type Parameters:
      T - the setting type
      Parameters:
      key - the identifier for the setting
      def - the default value. For each call of getSetting() with a given key, the default value must be the same. def must not be null, but the value of def can be null.
      klass - the setting type (same as T)
      Returns:
      the corresponding value if the property has been set before, def otherwise
    • getAllPrefix

      public Map<String,String> getAllPrefix(String prefix)
      Gets all normal (string) settings that have a key starting with the prefix
      Parameters:
      prefix - The start of the key
      Returns:
      The key names of the settings
    • getAllPrefixCollectionKeys

      Gets all list settings that have a key starting with the prefix
      Parameters:
      prefix - The start of the key
      Returns:
      The key names of the list settings
    • addSensitive

      public void addSensitive(CredentialsAgent caller, String key)
      Description copied from interface: IPreferences
      Add sensitive keys
      Specified by:
      addSensitive in interface IPreferences
      Parameters:
      caller - The calling agent
      key - The key that may contain sensitive information
    • getSensitive

      Description copied from interface: IPreferences
      Get sensitive keys
      Specified by:
      getSensitive in interface IPreferences
      Returns:
      The sensitive keys
    • removeSensitive

      public void removeSensitive(String key)
      Description copied from interface: IPreferences
      Remove sensitive keys. This removes the key from the sensitive list and removes the stored preference value.
      Specified by:
      removeSensitive in interface IPreferences
      Parameters:
      key - The key to remove
    • populateSensitiveKeys

      private void populateSensitiveKeys()
      Populate the sensitive key set from preferences