public class Preferences
extends java.lang.Object
PreferenceType
Modifier and Type | Field and Description |
---|---|
private java.util.HashMap<java.lang.String,Pair<PreferenceType,java.lang.Object>> |
preferences
Preferences map
|
private java.io.File |
preferencesFile
File where store preferences
|
private PreferencesSerializer |
preferencesSerializer
Preferences serializer to save them
|
Constructor and Description |
---|
Preferences(java.io.File preferencesFile)
Create a new instance of Preferences
|
Modifier and Type | Method and Description |
---|---|
byte[] |
getArrayValue(java.lang.String name)
Get a byte[] from preferences
|
java.io.File |
getFileValue(java.lang.String name)
Get file from preferences
|
PreferenceType |
getPreferenceType(java.lang.String name)
Obtain the type of a preference
|
boolean |
getValue(java.lang.String name,
boolean defaultValue)
Get a boolean value from preferences
|
int |
getValue(java.lang.String name,
int defaultValue)
Get a int value from preferences
|
java.lang.String |
getValue(java.lang.String name,
java.lang.String defaultValue)
Get a String value from preferences
|
private void |
loadPreferences()
Load preferences
|
(package private) static java.lang.Object |
parse(java.lang.String serializedValue,
PreferenceType preferenceType)
Parse a serialized value to the real value depends on
PreferenceType |
private void |
savePreferences()
Save preferences
|
(package private) static java.lang.String |
serialize(java.lang.Object value,
PreferenceType preferenceType)
Serialize a value depends on
PreferenceType |
void |
setValue(java.lang.String name,
boolean value)
Define/change a boolean value
|
void |
setValue(java.lang.String name,
byte[] value)
Define/change a byte[] value
|
void |
setValue(java.lang.String name,
java.io.File value)
Define/change a File value
|
void |
setValue(java.lang.String name,
int value)
Define/change a int value
|
void |
setValue(java.lang.String name,
java.lang.String value)
Define/change a String value
|
private final java.util.HashMap<java.lang.String,Pair<PreferenceType,java.lang.Object>> preferences
private final java.io.File preferencesFile
private final PreferencesSerializer preferencesSerializer
public Preferences(java.io.File preferencesFile)
preferencesFile
- File where read/write preferences may not actually existsstatic java.lang.Object parse(java.lang.String serializedValue, PreferenceType preferenceType)
PreferenceType
serializedValue
- Serialized valuepreferenceType
- Preference typestatic java.lang.String serialize(java.lang.Object value, PreferenceType preferenceType)
PreferenceType
value
- Value to serializepreferenceType
- Preference typeprivate void loadPreferences()
private void savePreferences()
public byte[] getArrayValue(java.lang.String name)
name
- Preference namenull
if not existspublic java.io.File getFileValue(java.lang.String name)
name
- preference namenull
if not existspublic PreferenceType getPreferenceType(java.lang.String name)
name
- Preference namenull
if preference dosen't existspublic boolean getValue(java.lang.String name, boolean defaultValue)
name
- Preference namedefaultValue
- Value to store and return if preference not already existspublic int getValue(java.lang.String name, int defaultValue)
name
- Preference namedefaultValue
- Value to store and return if preference not already existspublic java.lang.String getValue(java.lang.String name, java.lang.String defaultValue)
name
- Preference namedefaultValue
- Value to store and return if preference not already existspublic void setValue(java.lang.String name, boolean value)
name
- Preference namevalue
- New valuepublic void setValue(java.lang.String name, byte[] value)
name
- Preference namevalue
- New valuepublic void setValue(java.lang.String name, java.io.File value)
name
- Preference namevalue
- New valuepublic void setValue(java.lang.String name, int value)
name
- Preference namevalue
- New valuepublic void setValue(java.lang.String name, java.lang.String value)
name
- Preference namevalue
- New value