SyncDocument
- Kotlin
- Java
SyncDatabase stores a logical document object. When the data is changed by the user, it is automatically saved to SyncDatabase with the given name.
Summary
Public methods | |
---|---|
String |
Returns the path of the current node. |
SyncDocument |
Returns the child node with the given name. |
SyncDocument |
Returns the child node of the given path based on the current node. |
T? |
Returns the data of the current node deserialized into the given type. |
ResultCompat<Boolean> |
Sets the given value to the specified child node or the current node. |
ResultCompat<Boolean> |
Deletes the item at the given path in the current node. |
ResultCompat<Boolean> |
If the current node is an array, adds the given items at the specified position. |
ResultCompat<Boolean> |
If the current node is an array, adds the given item at the end. |
ResultCompat<Boolean> |
If the current node is an array, deletes the specified number of items from the given position. |
ResultCompat<Boolean> |
If the current node is an array, deletes the specified number of items from the given position. |
void |
Registers a callback to receive document data change and error events. |
void |
Removes the callback from the current document. |
Public properties | |
---|---|
SyncDatabase |
Returns the singleton object SyncDatabase. |
Returns the top-level node. | |
Returns the parent node. | |
String? |
Returns the serialized JSON string. |
SyncDocument is automatically managed by SyncDatabase. Do not call the constructor directly.
Public methods
key()
fun key(): String
Returns the path of the current node.
Returns | |
---|---|
String | Path of the current node |
child()
fun child(key: String): SyncDocument
Returns the child node with the given name.
Parameters | |
---|---|
String | Child node name |
Returns | |
---|---|
SyncDocument | Child node |
paths()
fun paths(vararg key: String): SyncDocument
Returns the child node of the given path based on the current node.
Parameters | |
---|---|
vararg String | Array of child node paths |
Returns | |
---|---|
SyncDocument | Child node |
value()
fun <T> value(clazz: Class<T>): T?
Returns the data of the current node deserialized into the given type.
Parameters | |
---|---|
Class<T> | POJO class to serialize |
Returns | |
---|---|
T? | Deserialized object |
If some variables of the POJO class cannot be found in the serialized JSON string, null
is returned.
setKeyValue()
fun setKeyValue(value: Object, key: String = null): ResultCompat<Boolean>
Sets the given value to the specified child node or the current node.
Parameters | |
---|---|
@Nullable Object | Set up data |
String | Child node path |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
unsetKeyValue()
fun unsetKeyValue(key: String): ResultCompat<Boolean>
Deletes the item at the specified path from the current node.
Parameters | |
---|---|
String | Child node path |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
insertToArray()
fun insertToArray(pos: Int, vararg value: Object): ResultCompat<Boolean>
If the current node is an array, adds the given items at the specified position.
Parameters | |
---|---|
Int | Position to add |
vararg Object | Array of values to add |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
updateInArray()
fun updateInArray(pos: Int, vararg value: Object): ResultCompat<Boolean>
If the current node is an array, overwrites the given items at the specified position.
Parameters | |
---|---|
Int | Position to overwrite |
vararg Object | Array of values to overwrite |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
deleteInArray()
fun deleteInArray(pos: Int, count: Int = 1): ResultCompat<Boolean>
If the current node is an array, removes the specified number of items starting from the given position.
Parameters | |
---|---|
Int | Position to remove |
Int | Number of items to remove |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
addDocumentEventListener()
fun addDocumentEventListener(listener: DocumentEventListener)
Registers a callback to receive document data change and error events.
Parameters | |
---|---|
DocumentEventListener | DocumentEventListener |
removeDocumentEventListener()
fun removeDocumentEventListener(listener: DocumentEventListener)
Removes the callback from the current document.
Parameters | |
---|---|
DocumentEventListener | DocumentEventListener |
SyncDatabase is a logical document object stored in the SyncDatabase. When data is modified by the user, it is automatically saved in the SyncDatabase with the given name.
Summary
Public methods | |
---|---|
@NonNull SyncDatabase |
Returns the SyncDatabase singleton object. |
@Nullable SyncDocument |
Returns the topmost node. |
@Nullable SyncDocument |
Returns the parent node. |
@Nullable String |
Returns a serialized JSON string. |
String |
Returns the path of the current node. |
SyncDocument |
Returns the child node with the given name. |
SyncDocument |
Returns the child nodes of the given path relative to the current node. |
@Nullable T |
Deserializes and returns the data of the current node as the given type. |
ResultCompat<Boolean> |
Sets the value of the current node. |
ResultCompat<Boolean> |
Sets the value of the child node at the given path from the current node. |
ResultCompat<Boolean> |
Deletes the item at the given path in the current node. |
ResultCompat<Boolean> |
If the current node is an array, it deletes the specified number of items starting at the given position. |
ResultCompat<Boolean> |
If the current node is an array, adds the given items at the specified position. |
ResultCompat<Boolean> |
If the current node is an array, adds the given item to the end. |
ResultCompat<Boolean> |
If the current node is an array, overwrites the given items at the given position. |
ResultCompat<Boolean> |
"If the current node is an array, it deletes the item at the given position." |
void |
Registers a callback to receive document data changes and error events. |
void |
Removes the callback from the current document. |
SyncDocument is automatically managed by the SyncDatabase. Do not call the constructor directly.
Public methods
getDatabase()
public final @NonNull SyncDatabase getDatabase()
Returns the SyncDatabase singleton object.
Returns | |
---|---|
@NonNull SyncDatabase | SyncDatabaseThe singleton object |
getRoot()
public final @Nullable SyncDocument getRoot()
Returns the topmost node.
Returns | |
---|---|
@Nullable SyncDocument | Topmost node |
getParent()
public final @Nullable SyncDocument getParent()
Returns the parent node.
Returns | |
---|---|
@Nullable SyncDocument | Parent node |
getJsonString()
public final @Nullable String getJsonString()
Returns a serialized JSON string.
Returns | |
---|---|
@Nullable String | Serialized JSON string |
key()
public final @NonNull String key()
Returns the path of the current node.
Returns | |
---|---|
@NonNull String | The path of the current node |
child()
public @NonNull SyncDocument child(@NonNull String key)
Returns the child node with the given name.
Parameters | |
---|---|
@NonNull String | Child node name |
Returns | |
---|---|
@NonNull SyncDocument | Child node |
paths()
public final @NonNull SyncDocument paths(@NonNull String... key)
Returns the child nodes of the given path relative to the current node.
Parameters | |
---|---|
@NonNull String... | Array of child node paths |
Returns | |
---|---|
@NonNull SyncDocument | Child node |
value()
public final @Nullable <T> value(clazz: Class<T>)
Deserializes and returns the data of the current node as the given type.
Parameters | |
---|---|
Class<T> | The POJO class to be serialized |
Returns | |
---|---|
@Nullable T | Deserialized object |
If some variables of the POJO class cannot be found in the Json string, null
is returned.
setKeyValue()
public final void setKeyValue(@Nullable Object value)
Removes the item at the given path from the current node.
Parameters | |
---|---|
@Nullable Object | Data to set |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
setKeyValue()
public final ResultCompat<Boolean> setKeyValue(@Nullable Object value, String key)
Sets the value of the current node.
Parameters | |
---|---|
@Nullable Object | Set up data |
String | Child node path |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
unsetKeyValue()
public final ResultCompat<Boolean> unsetKeyValue(@NonNull String key)
Deletes the item at the given path from the current node.
Parameters | |
---|---|
String | Child node path |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
insertToArray()
public final ResultCompat<Boolean> insertToArray(int pos, Object... value)
If the current node is an array, adds the given items at the given position.
Parameters | |
---|---|
int | Position to add |
Object... | Array of values to add |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
updateInArray()
public final ResultCompat<Boolean> updateInArray(int pos, Object... value)
If the current node is an array, overwrites the item at the given position.
Parameters | |
---|---|
int | Position to override |
Object... | Array of values to override |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
deleteInArray()
public final ResultCompat<Boolean> deleteInArray(int pos)
If the current node is an array, deletes the item at the specified position.
Parameters | |
---|---|
int | Position to delete |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
deleteInArray()
public final ResultCompat<Boolean> deleteInArray(int pos, int count)
If the current node is an array, deletes the specified number of items from the given position.
Parameters | |
---|---|
int | Position to delete |
int | Number of items to delete |
Returns | |
---|---|
ResultCompat<Boolean> | ResultCompat |
addDocumentEventListener()
public final void addDocumentEventListener(@NonNull DocumentEventListener listener)
Registers a callback to receive document data changes and error events.
Parameters | |
---|---|
@NonNull DocumentEventListener | DocumentEventListener |
removeDocumentEventListener()
public final void removeDocumentEventListener(@NonNull DocumentEventListener listener)
Removes the callback from the current document.
Parameters | |
---|---|
@NonNull DocumentEventListener | DocumentEventListener |