Class Dictionary

java.lang.Object
com.couchbase.lite.Dictionary
All Implemented Interfaces:
DictionaryInterface, com.couchbase.lite.internal.fleece.FLEncodable, Iterable<String>
Direct Known Subclasses:
MutableDictionary

public class Dictionary extends Object implements DictionaryInterface, com.couchbase.lite.internal.fleece.FLEncodable, Iterable<String>
Dictionary provides readonly access to dictionary data.
  • Method Details

    • toMutable

      @NonNull public MutableDictionary toMutable()
      Return a mutable copy of the dictionary
      Returns:
      the MutableDictionary instance
    • count

      public int count()
      Gets the number of the entries in the dictionary.
      Specified by:
      count in interface DictionaryInterface
      Returns:
      the size of the dictionary
    • 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 interface DictionaryInterface
      Parameters:
      key - the key
      Returns:
      the boolean value representing whether a property exists or not.
    • getKeys

      @NonNull public List<String> getKeys()
      Specified by:
      getKeys in interface DictionaryInterface
    • 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 interface DictionaryInterface
      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 interface DictionaryInterface
      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 interface DictionaryInterface
      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 interface DictionaryInterface
      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 interface DictionaryInterface
      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 interface DictionaryInterface
      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 interface DictionaryInterface
      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 interface DictionaryInterface
      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 interface DictionaryInterface
      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 interface DictionaryInterface
      Parameters:
      key - the key
      Returns:
      the Date value or null.
    • getArray

      @Nullable public Array getArray(@NonNull String key)
      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 interface DictionaryInterface
      Parameters:
      key - the key.
      Returns:
      the Array object.
    • getDictionary

      @Nullable public Dictionary getDictionary(@NonNull String key)
      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 interface DictionaryInterface
      Parameters:
      key - the key.
      Returns:
      the Dictionary object or null if the key doesn't exist.
    • 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 interface DictionaryInterface
      Returns:
      the Map object representing the content of the current object in the JSON format.
    • toJSON

      @NonNull public String toJSON() throws CouchbaseLiteException
      Encode a Dictionary as a JSON string
      Specified by:
      toJSON in interface DictionaryInterface
      Returns:
      JSON encoded representation of the Dictionary
      Throws:
      CouchbaseLiteException - on encoder failure.
    • iterator

      @NonNull public Iterator<String> iterator()
      An iterator over keys of this Dictionary. A call to the next() method of the returned iterator will throw a ConcurrentModificationException, if the MutableDictionary is modified while it is in use.
      Specified by:
      iterator in interface Iterable<String>
      Returns:
      an iterator over the dictionary's keys.
    • encodeTo

      @Internal("This method is not part of the public API") public void encodeTo(@NonNull com.couchbase.lite.internal.fleece.FLEncoder enc)
      Specified by:
      encodeTo in interface com.couchbase.lite.internal.fleece.FLEncodable
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      @NonNull public String toString()
      Overrides:
      toString in class Object