Interface IPreferences
-
- All Known Implementing Classes:
AbstractPreferences
,MemoryPreferences
,Preferences
public interface IPreferences
Interface for preference handling. Allows to save and retrieve user defined settings. The backend storage depends on the implementation.- Since:
- 12847
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
addKeyPreferenceChangeListener(String key, PreferenceChangedListener listener)
Adds a listener that only listens to changes in one preferencevoid
addPreferenceChangeListener(PreferenceChangedListener listener)
Adds a new preferences listener.default String
get(String key)
Get settings value for a certain key.String
get(String key, String def)
Get settings value for a certain key and provide a default value.default boolean
getBoolean(String key)
Gets a boolean preferenceboolean
getBoolean(String key, boolean def)
Gets a boolean preferencedouble
getDouble(String key, double def)
Gets a double preferenceint
getInt(String key, int def)
Gets an integer preferenceSet<String>
getKeySet()
Get the set of all keys that are mapped to a value in this preferences.default List<String>
getList(String key)
Get a list of values for a certain keyList<String>
getList(String key, List<String> def)
Get a list of values for a certain keydefault List<List<String>>
getListOfLists(String key)
Get an array of values (list of lists) for a certain keyList<List<String>>
getListOfLists(String key, List<List<String>> def)
Get an array of values (list of lists) for a certain keydefault List<Map<String,String>>
getListOfMaps(String key)
Gets a list of key/value maps.List<Map<String,String>>
getListOfMaps(String key, List<Map<String,String>> def)
Gets a list of key/value maps.long
getLong(String key, long def)
Gets a long preferenceboolean
put(String key, String value)
Set a value for a certain setting.boolean
putBoolean(String key, boolean value)
Set a boolean value for a certain setting.boolean
putDouble(String key, double value)
Set a boolean value for a certain setting.boolean
putInt(String key, int value)
Set an integer value for a certain setting.boolean
putList(String key, List<String> value)
Set a list of values for a certain key.boolean
putListOfLists(String key, List<List<String>> value)
Set an array of values (list of lists) for a certain key.boolean
putListOfMaps(String key, List<Map<String,String>> value)
Set an a list of key/value maps.boolean
putLong(String key, long value)
Set a long value for a certain setting.void
removeKeyPreferenceChangeListener(String key, PreferenceChangedListener listener)
Removes a listener that only listens to changes in one preferencevoid
removePreferenceChangeListener(PreferenceChangedListener listener)
Removes a preferences listener.
-
-
-
Method Detail
-
addPreferenceChangeListener
void addPreferenceChangeListener(PreferenceChangedListener listener)
Adds a new preferences listener.- Parameters:
listener
- The listener to add
-
removePreferenceChangeListener
void removePreferenceChangeListener(PreferenceChangedListener listener)
Removes a preferences listener.- Parameters:
listener
- The listener to remove
-
addKeyPreferenceChangeListener
void addKeyPreferenceChangeListener(String key, PreferenceChangedListener listener)
Adds a listener that only listens to changes in one preference- Parameters:
key
- The preference key to listen tolistener
- The listener to add.
-
removeKeyPreferenceChangeListener
void removeKeyPreferenceChangeListener(String key, PreferenceChangedListener listener)
Removes a listener that only listens to changes in one preference- Parameters:
key
- The preference key to listen tolistener
- The listener to add.
-
get
String get(String key, String def)
Get settings value for a certain key and provide a default value.- 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
-
get
default String get(String key)
Get settings value for a certain key.- Parameters:
key
- the identifier for the setting- Returns:
- "" if there is nothing set for the preference key, the corresponding value otherwise. The result is not null.
-
put
boolean put(String key, String value)
Set a value for a certain setting.- 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
boolean getBoolean(String key, boolean def)
Gets a boolean preference- 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
-
getBoolean
default boolean getBoolean(String key)
Gets a boolean preference- Parameters:
key
- The preference key- Returns:
- The boolean or
false
if it could not be parsed
-
putBoolean
boolean putBoolean(String key, boolean value)
Set a boolean value for a certain setting.- Parameters:
key
- the unique identifier for the settingvalue
- The new value- Returns:
true
, if something has changed (i.e. value is different than before)- Since:
- 12840
-
getInt
int getInt(String key, int def)
Gets an integer preference- Parameters:
key
- The preference keydef
- The default value to use- Returns:
- The integer
- Since:
- 12840
-
putInt
boolean putInt(String key, int value)
Set an integer value for a certain setting.- Parameters:
key
- the unique identifier for the settingvalue
- The new value- Returns:
true
, if something has changed (i.e. value is different than before)- Since:
- 12840
-
getLong
long getLong(String key, long def)
Gets a long preference- 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
boolean putLong(String key, long value)
Set a long value for a certain setting.- 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
double getDouble(String key, double def)
Gets a double preference- 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
boolean putDouble(String key, double value)
Set a boolean value for a certain setting.- Parameters:
key
- the unique identifier for the settingvalue
- The new value- Returns:
true
, if something has changed (i.e. value is different than before)- Since:
- 12840
-
getList
List<String> getList(String key, List<String> def)
Get a list of values for a certain key- Parameters:
key
- the identifier for the settingdef
- the default value.- Returns:
- the corresponding value if the property has been set before,
def
otherwise - Since:
- 12840
-
getList
default List<String> getList(String key)
Get a list of values for a certain key- Parameters:
key
- the identifier for the setting- Returns:
- the corresponding value if the property has been set before, an empty list otherwise.
- Since:
- 12840
-
putList
boolean putList(String key, List<String> value)
Set a list of values for a certain key.- Parameters:
key
- the identifier for the settingvalue
- The new value- Returns:
true
, if something has changed (i.e. value is different than before)- Since:
- 12840
-
getListOfLists
List<List<String>> getListOfLists(String key, List<List<String>> def)
Get an array of values (list of lists) for a certain key- Parameters:
key
- the identifier for the settingdef
- the default value.- Returns:
- the corresponding value if the property has been set before,
def
otherwise - Since:
- 12840
-
getListOfLists
default List<List<String>> getListOfLists(String key)
Get an array of values (list of lists) for a certain key- Parameters:
key
- the identifier for the setting- Returns:
- the corresponding value if the property has been set before, an empty list otherwise
- Since:
- 12840
-
putListOfLists
boolean putListOfLists(String key, List<List<String>> value)
Set an array of values (list of lists) for a certain key.- Parameters:
key
- the identifier for the settingvalue
- the new value- Returns:
true
, if something has changed (i.e. value is different than before)- Since:
- 12840
-
getListOfMaps
List<Map<String,String>> getListOfMaps(String key, List<Map<String,String>> def)
Gets a list of key/value maps.- 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 - Since:
- 12840
-
getListOfMaps
default List<Map<String,String>> getListOfMaps(String key)
Gets a list of key/value maps.- Parameters:
key
- the key to search at- Returns:
- the corresponding value if the property has been set before, an empty list otherwise
- Since:
- 12840
-
putListOfMaps
boolean putListOfMaps(String key, List<Map<String,String>> value)
Set an a list of key/value maps.- Parameters:
key
- the key to store the list invalue
- a list of key/value maps- Returns:
true
if the value was changed- Since:
- 12840
-
-