Class MemoryPreferences

  • All Implemented Interfaces:
    IPreferences

    public class MemoryPreferences
    extends AbstractPreferences
    Preferences implementation that keeps all settings in memory. Holds saved preferences for the current session, but does not retain any data when the program terminates.
    Since:
    12906
    • Field Detail

      • settings

        private final java.util.Map<java.lang.String,​Setting<?>> settings
    • Method Detail

      • putSetting

        public boolean putSetting​(java.lang.String key,
                                  Setting<?> setting)
        Description copied from class: AbstractPreferences
        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.
        Specified by:
        putSetting in class AbstractPreferences
        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 <T extends Setting<?>> T getSetting​(java.lang.String key,
                                                   T def,
                                                   java.lang.Class<T> klass)
        Description copied from class: AbstractPreferences
        Get settings value for a certain key and provide default a value.
        Specified by:
        getSetting in class AbstractPreferences
        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
      • getKeySet

        public java.util.Set<java.lang.String> getKeySet()
        Description copied from interface: IPreferences
        Get the set of all keys that are mapped to a value in this preferences.
        Returns:
        the set of all keys