public class UserPreferences extends java.lang.Object implements KeyValueStorage
| Modifier and Type | Class and Description |
|---|---|
static class |
UserPreferences.Chunk
Represents a chunk of a string data.
|
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
fwdUser
The current session FWD user.
|
private static java.lang.String |
HEAD_KEY
The head key
|
private static CentralLogger |
LOG
Logger
|
private static int |
MAXIMAL_STRING_LENGTH
The maximal string length for values
|
private com.fasterxml.jackson.databind.ObjectMapper |
objectMapper
Maps an object into its json presentation and back
|
private java.util.prefs.Preferences |
preferences
The Preferences node as root
|
private java.lang.String |
storageId
The unique in-app user storage id.
|
| Constructor and Description |
|---|
UserPreferences(java.lang.String storageId,
java.lang.String fwdUser)
Public constructor.
|
| Modifier and Type | Method and Description |
|---|---|
private java.lang.String |
collectChunks(java.util.prefs.Preferences node,
UserPreferences.Chunk head)
Collect stored chunks into the string value of the given key.
|
void |
delete(java.lang.String key)
Deletes the given key and its value from this storage.
|
private void |
flushChanges()
Flushes the current changes into this storage backend.
|
private java.lang.String |
formUniqueUserKey(java.lang.String originalKey)
Returns the key with FWD user name and storageId in the prefix.
|
java.lang.Boolean |
getBoolean(java.lang.String key)
Retrieves the boolean value of the given key from this storage.
|
private UserPreferences.Chunk |
getChunk(java.util.prefs.Preferences node,
java.lang.String chunkKey)
Retrieves the next chunk of stored data.
|
private int |
getMaximalValueSize()
Returns the maximal value size that can be stored into this storage backend.
|
private java.lang.String |
getNextChunkKey(UserPreferences.Chunk head,
int chunkNumber)
Returns the next chunk key.
|
java.lang.Number |
getNumber(java.lang.String key)
Retrieves the value of the given key from this storage.
|
private java.util.prefs.Preferences |
getPreferencesFor(java.lang.String key)
Returns the node assigned for the given key.
|
java.lang.String |
getStorageId()
Returns the storage id for the logged in user.
|
java.lang.String |
getString(java.lang.String key)
Retrieves the string value for the given key from this storage.
|
private UserPreferences.Chunk |
retrieveSimpleValue(java.lang.String key)
Returns the chunk with the simple value (Boolean or Number) for the given key.
|
private void |
saveByChunks(java.lang.String key,
java.lang.String value)
Saves the string value of this key in this storage by splitting it into chunks in order
to fit value capacity limits of this storage backend.
|
private void |
saveHeadChunk(java.util.prefs.Preferences headNode,
java.lang.String key,
UserPreferences.Chunk head)
Stores the head chunk with the given key within this storage backend.
|
private void |
saveSimpleValue(java.lang.String key,
UserPreferences.Chunk chunk)
Saves a simple value (Boolean or Number) under the given key.
|
void |
setBoolean(java.lang.String key,
java.lang.Boolean value)
Saves the boolean value of this key in this storage.
|
void |
setNumber(java.lang.String key,
java.lang.Number value)
Saves the number value of this key in this storage.
|
void |
setString(java.lang.String key,
java.lang.String value)
Saves the string value for this key in this storage.
|
private void |
setUniqueHeadName(UserPreferences.Chunk head)
Sets the unique name to the given head chunk.
|
private static final CentralLogger LOG
private static final java.lang.String HEAD_KEY
private static final int MAXIMAL_STRING_LENGTH
private final java.util.prefs.Preferences preferences
private final com.fasterxml.jackson.databind.ObjectMapper objectMapper
private final java.lang.String storageId
private final java.lang.String fwdUser
public UserPreferences(java.lang.String storageId,
java.lang.String fwdUser)
storageId - The unique in-app user storage idfwdUser - The FWD user name.public java.lang.Number getNumber(java.lang.String key)
getNumber in interface KeyValueStoragekey - The given keypublic void setNumber(java.lang.String key,
java.lang.Number value)
setNumber in interface KeyValueStoragekey - The given keyvalue - The value of the given keypublic java.lang.Boolean getBoolean(java.lang.String key)
getBoolean in interface KeyValueStoragekey - The given keypublic void setBoolean(java.lang.String key,
java.lang.Boolean value)
setBoolean in interface KeyValueStoragekey - The given keyvalue - The value of the given keypublic java.lang.String getString(java.lang.String key)
getString in interface KeyValueStoragekey - The given keypublic void setString(java.lang.String key,
java.lang.String value)
setString in interface KeyValueStoragekey - The given keyvalue - The string value of the given keypublic void delete(java.lang.String key)
delete in interface KeyValueStoragekey - The given keypublic java.lang.String getStorageId()
getStorageId in interface KeyValueStorageprivate UserPreferences.Chunk retrieveSimpleValue(java.lang.String key)
key - The given keyprivate void saveSimpleValue(java.lang.String key,
UserPreferences.Chunk chunk)
key - The given keychunk - The chunk to be savedprivate java.lang.String collectChunks(java.util.prefs.Preferences node,
UserPreferences.Chunk head)
node - The Preferences node for the keyhead - The first chunkprivate void saveByChunks(java.lang.String key,
java.lang.String value)
key - The given keyvalue - The string value of the given keyprivate void setUniqueHeadName(UserPreferences.Chunk head)
head - The first chunkprivate java.lang.String getNextChunkKey(UserPreferences.Chunk head, int chunkNumber)
head - A chunk of the stored data valuechunkNumber - The current chunk numberprivate void saveHeadChunk(java.util.prefs.Preferences headNode,
java.lang.String key,
UserPreferences.Chunk head)
throws com.fasterxml.jackson.core.JsonProcessingException
headNode - The Preferences node for the head keykey - The given keyhead - The first chunkcom.fasterxml.jackson.core.JsonProcessingExceptionprivate void flushChanges()
private int getMaximalValueSize()
private UserPreferences.Chunk getChunk(java.util.prefs.Preferences node, java.lang.String chunkKey)
node - The preferences nodechunkKey - The chunk keyprivate java.util.prefs.Preferences getPreferencesFor(java.lang.String key)
key - The given keyprivate java.lang.String formUniqueUserKey(java.lang.String originalKey)
originalKey - The key to be processed.