Package com.couchbase.lite
Class MutableDocument
java.lang.Object
com.couchbase.lite.Document
com.couchbase.lite.MutableDocument
- All Implemented Interfaces:
DictionaryInterface
,MutableDictionaryInterface
,Iterable<String>
A Couchbase Lite Document. A document has key/value properties like a Map.
-
Constructor Summary
ConstructorDescriptionCreates a new Document object with a new random UUID.Creates a new Document with the given ID.MutableDocument
(String id, String json) Creates a new Document with the given ID and content from the passed JSON string.MutableDocument
(String id, Map<String, Object> data) Creates a new Document with a given ID and content from the passed Map.MutableDocument
(Map<String, Object> data) Creates a new Document with a new random UUID and the map as the content. -
Method Summary
Modifier and TypeMethodDescriptionGet a property's value as a Array.getDictionary
(String key) Get a property's value as a Dictionary.Removes the mapping for a key from this DictionarySet an Array value for the given keySet a Blob value for the given keysetBoolean
(String key, boolean value) Set a boolean value for the given keyPopulate a document with content from a Map.Set a Date value for the given keysetDictionary
(String key, Dictionary value) Set a Dictionary value for the given keySet a double value for the given keySet a float value for the given keySet a integer value for the given keyPopulate a document with content from a JSON string.Set a long value for the given keySet a Number value for the given keySet a String value for the given keySet an object value by key.toJSON()
Unimplemented: Mutable objects may not be encoded as JSONReturns the copy of this MutableDocument object.Methods inherited from class com.couchbase.lite.Document
contains, count, equals, getBlob, getBoolean, getCollection, getContent, getDate, getDouble, getFloat, getId, getInt, getKeys, getLong, getNumber, getRevisionID, getSequence, getString, getTimestamp, getValue, hashCode, iterator, setContent, toMap, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.couchbase.lite.DictionaryInterface
contains, count, getBlob, getBoolean, getDate, getDouble, getFloat, getInt, getKeys, getLong, getNumber, getString, getValue, toMap
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
MutableDocument
public MutableDocument()Creates a new Document object with a new random UUID. The created document will be saved into a database when you call the Database's save(Document) method with the document object given. -
MutableDocument
Creates a new Document with the given ID. If the id is null, the document will be created with a new random UUID. The created document will be saved into a database when you call the Database's save(Document) method with the document object given.- Parameters:
id
- the document ID or null.
-
MutableDocument
Creates a new Document with a new random UUID and the map as the content. Allowed value types are List, Date, Map, Number, null, String, Array, Blob, and Dictionary. If present, Lists, Maps and Dictionaries may contain only the above types. The created document will be saved into a database when you call Database.save(Document) with this document object.- Parameters:
data
- the Map object
-
MutableDocument
Creates a new Document with a given ID and content from the passed Map. If the id is null, the document will be created with a new random UUID. Allowed value types are List, Date, Map, Number, null, String, Array, Blob, and Dictionary. The List and Map must contain only the above types. The created document will be saved into a database when you call the Database's save(Document) method with the document object given.- Parameters:
id
- the document ID.data
- the Map object
-
MutableDocument
Creates a new Document with the given ID and content from the passed JSON string. If the id is null, the document will be created with a new random UUID. The created document will be saved into a database when you call the Database's save(Document) method with the document object given.- Parameters:
id
- the document ID or null.json
- the document content as a JSON string.
-
-
Method Details
-
toMutable
Returns the copy of this MutableDocument object. -
setData
Populate a document with content from a Map. Allowed value types are List, Date, Map, Number, null, String, Array, Blob, and Dictionary. If present, Lists, Maps and Dictionaries may contain only the above types. Setting the document content will replace the current data including the existing Array and Dictionary objects.- Specified by:
setData
in interfaceMutableDictionaryInterface
- Parameters:
data
- the dictionary object.- Returns:
- this Document instance
-
setJSON
Populate a document with content from a JSON string. Allowed value types are List, Date, Map, Number, null, String, Array, Blob, and Dictionary. If present, Lists, Maps and Dictionaries may contain only the above types. Setting the document content will replace the current data including the existing Array and Dictionary objects.- Specified by:
setJSON
in interfaceMutableDictionaryInterface
- Parameters:
json
- the dictionary object.- Returns:
- this Document instance
-
setValue
Set an object value by key. Allowed value types are List, Date, Map, Number, null, String, Array, Blob, and Dictionary. If present, Lists, Maps and Dictionaries may contain only the above types. An Date object will be converted to an ISO-8601 format string.- Specified by:
setValue
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the Object value.- Returns:
- this Document instance
-
setString
Set a String value for the given key- Specified by:
setString
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the String value.- Returns:
- this MutableDocument instance
-
setNumber
Set a Number value for the given key- Specified by:
setNumber
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the Number value.- Returns:
- this MutableDocument instance
-
setInt
Set a integer value for the given key- Specified by:
setInt
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the integer value.- Returns:
- this MutableDocument instance
-
setLong
Set a long value for the given key- Specified by:
setLong
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the long value.- Returns:
- this MutableDocument instance
-
setFloat
Set a float value for the given key- Specified by:
setFloat
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the float value.- Returns:
- this MutableDocument instance
-
setDouble
Set a double value for the given key- Specified by:
setDouble
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the double value.- Returns:
- this MutableDocument instance
-
setBoolean
Set a boolean value for the given key- Specified by:
setBoolean
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the boolean value.- Returns:
- this MutableDocument instance
-
setBlob
Set a Blob value for the given key- Specified by:
setBlob
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the Blob value.- Returns:
- this MutableDocument instance
-
setDate
Set a Date value for the given key- Specified by:
setDate
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the Date value.- Returns:
- this MutableDocument instance
-
setArray
Set an Array value for the given key- Specified by:
setArray
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the Array value.- Returns:
- this MutableDocument instance
-
setDictionary
Set a Dictionary value for the given key- Specified by:
setDictionary
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.value
- the Dictionary value.- Returns:
- this MutableDocument instance
-
remove
Removes the mapping for a key from this Dictionary- Specified by:
remove
in interfaceMutableDictionaryInterface
- Parameters:
key
- the key.- Returns:
- this MutableDocument instance
-
getArray
Get a property's value as a Array. Returns null if the property doesn't exists, or its value is not an array.- Specified by:
getArray
in interfaceDictionaryInterface
- Specified by:
getArray
in interfaceMutableDictionaryInterface
- Overrides:
getArray
in classDocument
- Parameters:
key
- the key.- Returns:
- the Array object.
-
getDictionary
Get a property's value as a Dictionary. Returns null if the property doesn't exists, or its value is not an dictionary.- Specified by:
getDictionary
in interfaceDictionaryInterface
- Specified by:
getDictionary
in interfaceMutableDictionaryInterface
- Overrides:
getDictionary
in classDocument
- Parameters:
key
- the key.- Returns:
- the Dictionary object or null if the key doesn't exist.
-
toJSON
Unimplemented: Mutable objects may not be encoded as JSON- Specified by:
toJSON
in interfaceDictionaryInterface
- Overrides:
toJSON
in classDocument
- Returns:
- never
- Throws:
CouchbaseLiteError
- always
-