Package com.couchbase.lite
Class Document
- java.lang.Object
-
- com.couchbase.lite.Document
-
- All Implemented Interfaces:
DictionaryInterface
,Iterable<String>
- Direct Known Subclasses:
MutableDocument
public class Document extends Object implements DictionaryInterface, Iterable<String>
Readonly version of the Document. Probably should be closeable.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(String key)
Tests whether a property exists or not.int
count()
Gets a number of the entries in the dictionary.boolean
equals(Object o)
Array
getArray(String key)
Get a property's value as a Array, which is a mapping object of an array value.Blob
getBlob(String key)
Gets a property's value as a Blob.boolean
getBoolean(String key)
Gets a property's value as a boolean.Date
getDate(String key)
Gets a property's value as a Date.Dictionary
getDictionary(String key)
Get a property's value as a Dictionary, which is a mapping object of a Dictionary value.double
getDouble(String key)
Gets a property's value as an double.float
getFloat(String key)
Gets a property's value as an float.String
getId()
return the document's ID.int
getInt(String key)
Gets a property's value as an int.List<String>
getKeys()
Get an List containing all keys, or an empty List if the document has no properties.long
getLong(String key)
Gets a property's value as an long.Number
getNumber(String key)
Gets a property's value as a Number.String
getRevisionID()
Get the document's revision id.long
getSequence()
Return the sequence number of the document in the database.String
getString(String key)
Gets a property's value as a String.Object
getValue(String key)
Gets a property's value as an object.int
hashCode()
Iterator<String>
iterator()
Gets an iterator over the keys of the document's propertiesString
toJSON()
Map<String,Object>
toMap()
Gets content of the current object as an Map.MutableDocument
toMutable()
Return a mutable copy of the documentString
toString()
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
getId
@NonNull public String getId()
return the document's ID.- Returns:
- the document's ID
-
getRevisionID
@Nullable public String getRevisionID()
Get the document's revision id. The revision id in the Document class is a constant while the revision id in the MutableDocument class is not. A newly created Document will have a null revision id. The revision id in a MutableDocument will be updated on save. The revision id format is opaque, which means its format has no meaning and shouldn't be parsed to get information.- Returns:
- the document's revision id
-
getSequence
public long getSequence()
Return the sequence number of the document in the database. The sequence number indicates how recently the document has been changed. Every time a document is updated, the database assigns it the next sequential sequence number. Thus, when a document's sequence number changes it means that the document been update (on-disk). If one document's sequence is different than another's, the document with the larger sequence number was changed more recently. Sequence numbers are not available for documents obtained from a replication filter. This method will always return 0 for such documents.- Returns:
- the sequence number of the document in the database.
-
toMutable
@NonNull public MutableDocument toMutable()
Return a mutable copy of the document- Returns:
- the MutableDocument instance
-
count
public int count()
Gets a number of the entries in the dictionary.- Specified by:
count
in interfaceDictionaryInterface
- Returns:
- the number of entries in the dictionary.
-
getKeys
@NonNull public List<String> getKeys()
Get an List containing all keys, or an empty List if the document has no properties.- Specified by:
getKeys
in interfaceDictionaryInterface
- Returns:
- all keys
-
getValue
@Nullable public Object getValue(@NonNull String key)
Gets a property's value as an object. The object types are Blob, Array, Dictionary, Number, or String based on the underlying data type; or nil if the property value is null or the property doesn't exist.- Specified by:
getValue
in interfaceDictionaryInterface
- Parameters:
key
- the key.- Returns:
- the object value or null.
-
getString
@Nullable public String getString(@NonNull String key)
Gets a property's value as a String. Returns null if the value doesn't exist, or its value is not a String.- Specified by:
getString
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- the String or null.
-
getNumber
@Nullable public Number getNumber(@NonNull String key)
Gets a property's value as a Number. Returns null if the value doesn't exist, or its value is not a Number.- Specified by:
getNumber
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- the Number or nil.
-
getInt
public int getInt(@NonNull String key)
Gets a property's value as an int. Floating point values will be rounded. The value `true` is returned as 1, `false` as 0. Returns 0 if the value doesn't exist or does not have a numeric value.- Specified by:
getInt
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- the int value.
-
getLong
public long getLong(@NonNull String key)
Gets a property's value as an long. Floating point values will be rounded. The value `true` is returned as 1, `false` as 0. Returns 0 if the value doesn't exist or does not have a numeric value.- Specified by:
getLong
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- the long value.
-
getFloat
public float getFloat(@NonNull String key)
Gets a property's value as an float. Integers will be converted to float. The value `true` is returned as 1.0, `false` as 0.0. Returns 0.0 if the value doesn't exist or does not have a numeric value.- Specified by:
getFloat
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- the float value.
-
getDouble
public double getDouble(@NonNull String key)
Gets a property's value as an double. Integers will be converted to double. The value `true` is returned as 1.0, `false` as 0.0. Returns 0.0 if the property doesn't exist or does not have a numeric value.- Specified by:
getDouble
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- the double value.
-
getBoolean
public boolean getBoolean(@NonNull String key)
Gets a property's value as a boolean. Returns true if the value exists, and is either `true` or a nonzero number.- Specified by:
getBoolean
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- the boolean value.
-
getBlob
@Nullable public Blob getBlob(@NonNull String key)
Gets a property's value as a Blob. Returns null if the value doesn't exist, or its value is not a Blob.- Specified by:
getBlob
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- the Blob value or null.
-
getDate
@Nullable public Date getDate(@NonNull String key)
Gets a property's value as a Date. JSON does not directly support dates, so the actual property value must be a string, which is then parsed according to the ISO-8601 date format (the default used in JSON.) Returns null if the value doesn't exist, is not a string, or is not parsable as a date. NOTE: This is not a generic date parser! It only recognizes the ISO-8601 format, with or without milliseconds.- Specified by:
getDate
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- the Date value or null.
-
getArray
@Nullable public Array getArray(@NonNull String key)
Get a property's value as a Array, which is a mapping object of an array value. Returns null if the property doesn't exists, or its value is not an Array.- Specified by:
getArray
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- The Array object or null.
-
getDictionary
@Nullable public Dictionary getDictionary(@NonNull String key)
Get a property's value as a Dictionary, which is a mapping object of a Dictionary value. Returns null if the property doesn't exists, or its value is not a Dictionary.- Specified by:
getDictionary
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- The Dictionary object or null.
-
toMap
@NonNull public Map<String,Object> toMap()
Gets content of the current object as an Map. The values contained in the returned Map object are all JSON based values.- Specified by:
toMap
in interfaceDictionaryInterface
- Returns:
- the Map object representing the content of the current object in the JSON format.
-
toJSON
@Nullable public String toJSON()
- Specified by:
toJSON
in interfaceDictionaryInterface
-
contains
public boolean contains(@NonNull String key)
Tests whether a property exists or not. This can be less expensive than getValue(String), because it does not have to allocate an Object for the property value.- Specified by:
contains
in interfaceDictionaryInterface
- Parameters:
key
- the key- Returns:
- the boolean value representing whether a property exists or not.
-
iterator
@NonNull public Iterator<String> iterator()
Gets an iterator over the keys of the document's properties
-
-