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 java.lang.Object implements IPreferences
Abstract implementation of theIPreferences
interface.- Since:
- 12847
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
KEY_SENSITIVE_KEYS
The preference key for sensitive keysprivate static java.util.Set<java.lang.String>
SENSITIVE_KEYS
A set of sensitive keys that should not be seen/distributed outside of specific callers (like aCredentialsAgent
)
-
Constructor Summary
Constructors Constructor Description AbstractPreferences()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addSensitive(CredentialsAgent caller, java.lang.String key)
Add sensitive keysjava.lang.String
get(java.lang.String key, java.lang.String def)
Get settings value for a certain key and provide a default value.java.util.Map<java.lang.String,java.lang.String>
getAllPrefix(java.lang.String prefix)
Gets all normal (string) settings that have a key starting with the prefixjava.util.List<java.lang.String>
getAllPrefixCollectionKeys(java.lang.String prefix)
Gets all list settings that have a key starting with the prefixabstract java.util.Map<java.lang.String,Setting<?>>
getAllSettings()
Gets a map of all settings that are currently storedboolean
getBoolean(java.lang.String key, boolean def)
Gets a boolean preferencedouble
getDouble(java.lang.String key, double def)
Gets a double preferenceint
getInt(java.lang.String key, int def)
Gets an integer preferencejava.util.List<java.lang.String>
getList(java.lang.String key, java.util.List<java.lang.String> def)
Get a list of values for a certain keyjava.util.List<java.util.List<java.lang.String>>
getListOfLists(java.lang.String key, java.util.List<java.util.List<java.lang.String>> def)
Get an array of values (list of lists) for a certain keyjava.util.List<java.util.Map<java.lang.String,java.lang.String>>
getListOfMaps(java.lang.String key, java.util.List<java.util.Map<java.lang.String,java.lang.String>> def)
Gets a list of key/value maps.long
getLong(java.lang.String key, long def)
Gets a long preferencejava.util.Collection<java.lang.String>
getSensitive()
Get sensitive keysabstract <T extends Setting<?>>
TgetSetting(java.lang.String key, T def, java.lang.Class<T> klass)
Get settings value for a certain key and provide default a value.private void
populateSensitiveKeys()
Populate the sensitive key set from preferencesboolean
put(java.lang.String key, java.lang.String value)
Set a value for a certain setting.boolean
putBoolean(java.lang.String key, boolean value)
Set a boolean value for a certain setting.boolean
putDouble(java.lang.String key, double value)
Set a boolean value for a certain setting.boolean
putInt(java.lang.String key, int value)
Set an integer value for a certain setting.boolean
putList(java.lang.String key, java.util.List<java.lang.String> value)
Set a list of values for a certain key.boolean
putListOfLists(java.lang.String key, java.util.List<java.util.List<java.lang.String>> value)
Set an array of values (list of lists) for a certain key.boolean
putListOfMaps(java.lang.String key, java.util.List<java.util.Map<java.lang.String,java.lang.String>> value)
Set an a list of key/value maps.boolean
putLong(java.lang.String key, long value)
Set a long value for a certain setting.abstract boolean
putSetting(java.lang.String key, Setting<?> setting)
Set a value for a certain setting.void
removeSensitive(java.lang.String key)
Remove sensitive keys.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.spi.preferences.IPreferences
addKeyPreferenceChangeListener, addPreferenceChangeListener, get, getBoolean, getKeySet, getList, getListOfLists, getListOfMaps, removeKeyPreferenceChangeListener, removePreferenceChangeListener
-
-
-
-
Field Detail
-
KEY_SENSITIVE_KEYS
private static final java.lang.String KEY_SENSITIVE_KEYS
The preference key for sensitive keys- See Also:
- Constant Field Values
-
SENSITIVE_KEYS
private static final java.util.Set<java.lang.String> SENSITIVE_KEYS
A set of sensitive keys that should not be seen/distributed outside of specific callers (like aCredentialsAgent
)
-
-
Constructor Detail
-
AbstractPreferences
public AbstractPreferences()
-
-
Method Detail
-
get
public java.lang.String get(java.lang.String key, java.lang.String def)
Description copied from interface:IPreferences
Get settings value for a certain key and provide a default value.- Specified by:
get
in interfaceIPreferences
- Parameters:
key
- the identifier for the settingdef
- 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(java.lang.String key, java.lang.String value)
Description copied from interface:IPreferences
Set a value for a certain setting.- Specified by:
put
in interfaceIPreferences
- Parameters:
key
- the unique identifier for the settingvalue
- 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(java.lang.String key, boolean def)
Description copied from interface:IPreferences
Gets a boolean preference- Specified by:
getBoolean
in interfaceIPreferences
- Parameters:
key
- The preference keydef
- 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(java.lang.String key, boolean value)
Description copied from interface:IPreferences
Set a boolean value for a certain setting.- Specified by:
putBoolean
in interfaceIPreferences
- Parameters:
key
- the unique identifier for the settingvalue
- The new value- Returns:
true
, if something has changed (i.e. value is different than before)
-
getInt
public int getInt(java.lang.String key, int def)
Description copied from interface:IPreferences
Gets an integer preference- Specified by:
getInt
in interfaceIPreferences
- Parameters:
key
- The preference keydef
- The default value to use- Returns:
- The integer
-
putInt
public boolean putInt(java.lang.String key, int value)
Description copied from interface:IPreferences
Set an integer value for a certain setting.- Specified by:
putInt
in interfaceIPreferences
- Parameters:
key
- the unique identifier for the settingvalue
- The new value- Returns:
true
, if something has changed (i.e. value is different than before)
-
getLong
public long getLong(java.lang.String key, long def)
Description copied from interface:IPreferences
Gets a long preference- Specified by:
getLong
in interfaceIPreferences
- Parameters:
key
- The preference keydef
- The default value to use- Returns:
- The long value or the default value if it could not be parsed
-
putLong
public boolean putLong(java.lang.String key, long value)
Description copied from interface:IPreferences
Set a long value for a certain setting.- Specified by:
putLong
in interfaceIPreferences
- Parameters:
key
- the unique identifier for the settingvalue
- The new value- Returns:
true
, if something has changed (i.e. value is different than before)
-
getDouble
public double getDouble(java.lang.String key, double def)
Description copied from interface:IPreferences
Gets a double preference- Specified by:
getDouble
in interfaceIPreferences
- Parameters:
key
- The preference keydef
- The default value to use- Returns:
- The double value or the default value if it could not be parsed
-
putDouble
public boolean putDouble(java.lang.String key, double value)
Description copied from interface:IPreferences
Set a boolean value for a certain setting.- Specified by:
putDouble
in interfaceIPreferences
- Parameters:
key
- the unique identifier for the settingvalue
- The new value- Returns:
true
, if something has changed (i.e. value is different than before)
-
getList
public java.util.List<java.lang.String> getList(java.lang.String key, java.util.List<java.lang.String> def)
Description copied from interface:IPreferences
Get a list of values for a certain key- Specified by:
getList
in interfaceIPreferences
- Parameters:
key
- the identifier for the settingdef
- the default value.- Returns:
- the corresponding value if the property has been set before,
def
otherwise
-
putList
public boolean putList(java.lang.String key, java.util.List<java.lang.String> value)
Description copied from interface:IPreferences
Set a list of values for a certain key.- Specified by:
putList
in interfaceIPreferences
- Parameters:
key
- the identifier for the settingvalue
- The new value- Returns:
true
, if something has changed (i.e. value is different than before)
-
getListOfLists
public java.util.List<java.util.List<java.lang.String>> getListOfLists(java.lang.String key, java.util.List<java.util.List<java.lang.String>> def)
Description copied from interface:IPreferences
Get an array of values (list of lists) for a certain key- Specified by:
getListOfLists
in interfaceIPreferences
- Parameters:
key
- the identifier for the settingdef
- the default value.- Returns:
- the corresponding value if the property has been set before,
def
otherwise
-
putListOfLists
public boolean putListOfLists(java.lang.String key, java.util.List<java.util.List<java.lang.String>> value)
Description copied from interface:IPreferences
Set an array of values (list of lists) for a certain key.- Specified by:
putListOfLists
in interfaceIPreferences
- Parameters:
key
- the identifier for the settingvalue
- the new value- Returns:
true
, if something has changed (i.e. value is different than before)
-
getListOfMaps
public java.util.List<java.util.Map<java.lang.String,java.lang.String>> getListOfMaps(java.lang.String key, java.util.List<java.util.Map<java.lang.String,java.lang.String>> def)
Description copied from interface:IPreferences
Gets a list of key/value maps.- Specified by:
getListOfMaps
in interfaceIPreferences
- Parameters:
key
- the key to search atdef
- the default value to use- Returns:
- the corresponding value if the property has been set before,
def
otherwise
-
putListOfMaps
public boolean putListOfMaps(java.lang.String key, java.util.List<java.util.Map<java.lang.String,java.lang.String>> value)
Description copied from interface:IPreferences
Set an a list of key/value maps.- Specified by:
putListOfMaps
in interfaceIPreferences
- Parameters:
key
- the key to store the list invalue
- a list of key/value maps- Returns:
true
if the value was changed
-
getAllSettings
public abstract java.util.Map<java.lang.String,Setting<?>> getAllSettings()
Gets a map of all settings that are currently stored- Returns:
- The settings
-
putSetting
public abstract boolean putSetting(java.lang.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 settingsetting
- 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(java.lang.String key, T def, java.lang.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 settingdef
- 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 ofdef
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 java.util.Map<java.lang.String,java.lang.String> getAllPrefix(java.lang.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
public java.util.List<java.lang.String> getAllPrefixCollectionKeys(java.lang.String prefix)
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, java.lang.String key)
Description copied from interface:IPreferences
Add sensitive keys- Specified by:
addSensitive
in interfaceIPreferences
- Parameters:
caller
- The calling agentkey
- The key that may contain sensitive information
-
getSensitive
public java.util.Collection<java.lang.String> getSensitive()
Description copied from interface:IPreferences
Get sensitive keys- Specified by:
getSensitive
in interfaceIPreferences
- Returns:
- The sensitive keys
-
removeSensitive
public void removeSensitive(java.lang.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 interfaceIPreferences
- Parameters:
key
- The key to remove
-
populateSensitiveKeys
private void populateSensitiveKeys()
Populate the sensitive key set from preferences
-
-