Package com.couchbase.lite
Class Dictionary
java.lang.Object
com.couchbase.lite.internal.BaseJFleeceCollection
com.couchbase.lite.AbstractJFleeceCollection<com.couchbase.lite.internal.fleece.MDict>
com.couchbase.lite.Dictionary
- All Implemented Interfaces:
DictionaryInterface
,com.couchbase.lite.internal.fleece.FleeceEncodable
,com.couchbase.lite.internal.fleece.JSONEncodable
,JFleeceCollectionInterface
,Iterable<String>
- Direct Known Subclasses:
MutableDictionary
public class Dictionary
extends AbstractJFleeceCollection<com.couchbase.lite.internal.fleece.MDict>
implements DictionaryInterface, Iterable<String>
Dictionary provides readonly access to dictionary data.
-
Field Summary
Fields inherited from class com.couchbase.lite.AbstractJFleeceCollection
contents, lock
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Dictionary
(com.couchbase.lite.internal.fleece.MDict dict) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Tests whether a property exists or not.boolean
Get a property's value as an Array.Gets a property's value as a Blob.boolean
getBoolean
(String key) Gets a property's value as a boolean.Gets a property's value as a Date.getDictionary
(String key) Get a property's value as a Dictionary.double
Gets a property's value as an double.float
Gets a property's value as an float.int
Gets a property's value as an int.getKeys()
long
Gets a property's value as an long.Gets a property's value as a Number.Gets a property's value as a String.<T> T
Gets a property's value as an object.Gets a property's value as an object.int
hashCode()
iterator()
An iterator over keys of this Dictionary.toMap()
Gets content of the current object as an Map.Return a mutable copy of the dictionarytoString()
Methods inherited from class com.couchbase.lite.AbstractJFleeceCollection
count, encodeTo, isEmpty, toJFleece, toJSON, willMutate
Methods inherited from class com.couchbase.lite.internal.BaseJFleeceCollection
asArray, asBlob, asBoolean, asDictionary, asNumber, asString, asValue, toBoolean, toDouble, toDouble, toFloat, toFloat, toInteger, toInteger, toJFleeceCollection, toLong, toLong
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface com.couchbase.lite.JFleeceCollectionInterface
count, isEmpty
-
Constructor Details
-
Dictionary
protected Dictionary(@NonNull com.couchbase.lite.internal.fleece.MDict dict)
-
-
Method Details
-
toMutable
Return a mutable copy of the dictionary- Specified by:
toMutable
in classAbstractJFleeceCollection<com.couchbase.lite.internal.fleece.MDict>
- Returns:
- the MutableDictionary instance
-
contains
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.
-
getKeys
- Specified by:
getKeys
in interfaceDictionaryInterface
-
getBoolean
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.
-
getInt
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
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
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
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.
-
getNumber
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.
-
getString
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.
-
getDate
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.
-
getBlob
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.
-
getArray
Get a property's value as an Array. 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.
-
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
- Parameters:
key
- the key.- Returns:
- the Dictionary object or null if the key doesn't exist.
-
getValue
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.
-
getValue
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 value at the index, or null if the value doesn't exist or is not of the given class.
-
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.
-
iterator
An iterator over keys of this Dictionary. A call to thenext()
method of the returned iterator will throw a ConcurrentModificationException, if the MutableDictionary is modified while it is in use. -
equals
-
hashCode
public int hashCode() -
toString
-