public abstract class UserPreference extends Object
Note: Implementing class must have an empty constructor to allow instantiation while runtime.
Constructor and Description |
---|
UserPreference()
Default constructor.
|
UserPreference(Map<String,String> preferences)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected Map<String,String> |
getDefaults()
Return the default values of this preference as a map.
|
Map<String,String> |
getPreferences() |
boolean |
getValue(String key,
boolean defaultValue) |
byte |
getValue(String key,
byte defaultValue) |
double |
getValue(String key,
double defaultValue) |
float |
getValue(String key,
float defaultValue) |
int |
getValue(String key,
int defaultValue) |
long |
getValue(String key,
long defaultValue) |
short |
getValue(String key,
short defaultValue) |
String |
getValue(String key,
String defaultValue) |
<T> T |
getValueFromJson(String key,
T defaultValue,
Class<T> type)
Method to get a more complex object from a JSON string.
|
void |
setPreferences(Map<String,String> preferences)
Method to set the preferences.
|
void |
setValue(String key,
Object value)
Method to set the given object as value.
|
void |
setValueToJson(String key,
Object value)
Method to set a more complex object explicitly as JSON.
|
protected Map<String,String> getDefaults()
public boolean getValue(String key, boolean defaultValue)
key
- The key.defaultValue
- The default value to return.public byte getValue(String key, byte defaultValue)
key
- The key.defaultValue
- The default value to return.public double getValue(String key, double defaultValue)
key
- The key.defaultValue
- The default value to return.public float getValue(String key, float defaultValue)
key
- The key.defaultValue
- The default value to return.public int getValue(String key, int defaultValue)
key
- The key.defaultValue
- The default value to return.public long getValue(String key, long defaultValue)
key
- The key.defaultValue
- The default value to return.public short getValue(String key, short defaultValue)
key
- The key.defaultValue
- The default value to return.public String getValue(String key, String defaultValue)
key
- The key.defaultValue
- The default value to return.public <T> T getValueFromJson(String key, T defaultValue, Class<T> type)
Note, that parsing is done on every request you do, so this might be slow on large objects. Also all parsing exceptions are logged and not thrown.
T
- Type of the object.key
- The key.defaultValue
- The default value.type
- The type of the object.public void setPreferences(Map<String,String> preferences)
preferences
- The preferences to set. These might overwrite existing ones.public void setValue(String key, Object value)
key
- The key.value
- The value to set. Use null to remove the value.public void setValueToJson(String key, Object value)
Note, that parsing is done on every request you do, so this might be slow on large objects. Also all parsing exceptions are logged and not thrown.
key
- The key.value
- The value to be set, if null, the key will be removed.Copyright © 2019 Communote team. All rights reserved.