Package com.couchbase.lite
Class Dictionary
- java.lang.Object
-
- com.couchbase.lite.Dictionary
-
- All Implemented Interfaces:
DictionaryInterface
,com.couchbase.lite.internal.fleece.FLEncodable
,java.lang.Iterable<java.lang.String>
- Direct Known Subclasses:
MutableDictionary
public class Dictionary extends java.lang.Object implements DictionaryInterface, com.couchbase.lite.internal.fleece.FLEncodable, java.lang.Iterable<java.lang.String>
Dictionary provides readonly access to dictionary data.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(java.lang.String key)
Tests whether a property exists or not.int
count()
Gets a number of the entries in the dictionary.void
encodeTo(com.couchbase.lite.internal.fleece.FLEncoder enc)
Internal method: Do not use.boolean
equals(java.lang.Object o)
Array
getArray(java.lang.String key)
Get a property's value as a Array, which is a mapping object of an array value.Blob
getBlob(java.lang.String key)
Gets a property's value as a Blob.boolean
getBoolean(java.lang.String key)
Gets a property's value as a boolean.java.util.Date
getDate(java.lang.String key)
Gets a property's value as a Date.Dictionary
getDictionary(java.lang.String key)
Get a property's value as a Dictionary, which is a mapping object of an dictionary value.double
getDouble(java.lang.String key)
Gets a property's value as an double.float
getFloat(java.lang.String key)
Gets a property's value as an float.int
getInt(java.lang.String key)
Gets a property's value as an int.java.util.List<java.lang.String>
getKeys()
long
getLong(java.lang.String key)
Gets a property's value as an long.java.lang.Number
getNumber(java.lang.String key)
Gets a property's value as a Number.java.lang.String
getString(java.lang.String key)
Gets a property's value as a String.java.lang.Object
getValue(java.lang.String key)
Gets a property's value as an object.int
hashCode()
java.util.Iterator<java.lang.String>
iterator()
java.lang.String
toJSON()
java.util.Map<java.lang.String,java.lang.Object>
toMap()
Gets content of the current object as an Map.MutableDictionary
toMutable()
Return a mutable copy of the dictionaryjava.lang.String
toString()
-
-
-
Method Detail
-
toMutable
@NonNull public MutableDictionary toMutable()
Return a mutable copy of the dictionary- Returns:
- the MutableDictionary instance
-
count
public int count()
Gets a number of the entries in the dictionary.- Specified by:
count
in interfaceDictionaryInterface
- Returns:
- the size of the dictionary
-
getKeys
@NonNull public java.util.List<java.lang.String> getKeys()
- Specified by:
getKeys
in interfaceDictionaryInterface
-
getValue
@Nullable public java.lang.Object getValue(@NonNull java.lang.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 java.lang.String getString(@NonNull java.lang.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 java.lang.Number getNumber(@NonNull java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.util.Date getDate(@NonNull java.lang.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 java.lang.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.
-
getDictionary
@Nullable public Dictionary getDictionary(@NonNull java.lang.String key)
Get a property's value as a Dictionary, which is a mapping object of an dictionary value. 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.
-
toMap
@NonNull public java.util.Map<java.lang.String,java.lang.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
@NonNull public java.lang.String toJSON()
- Specified by:
toJSON
in interfaceDictionaryInterface
-
contains
public boolean contains(@NonNull java.lang.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.
-
encodeTo
public void encodeTo(@NonNull com.couchbase.lite.internal.fleece.FLEncoder enc)
Internal method: Do not use.- Specified by:
encodeTo
in interfacecom.couchbase.lite.internal.fleece.FLEncodable
-
iterator
@NonNull public java.util.Iterator<java.lang.String> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.String>
-
equals
public boolean equals(@Nullable java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
@NonNull public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-