Class MutableDictionary

java.lang.Object
com.couchbase.lite.internal.BaseJFleeceCollection
com.couchbase.lite.AbstractJFleeceCollection<com.couchbase.lite.internal.fleece.MDict>
com.couchbase.lite.Dictionary
com.couchbase.lite.MutableDictionary
All Implemented Interfaces:
DictionaryInterface, com.couchbase.lite.internal.fleece.FleeceEncodable, com.couchbase.lite.internal.fleece.JSONEncodable, JFleeceCollectionInterface, MutableDictionaryInterface, Iterable<String>

public final class MutableDictionary extends Dictionary implements MutableDictionaryInterface
Mutable access to dictionary data.
  • Constructor Details

    • MutableDictionary

      public MutableDictionary()
      Construct a new empty MutableDictionary.
    • MutableDictionary

      public MutableDictionary(@NonNull Map<String,?> data)
      Creates a new MutableDictionary with content from the passed 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.
      Parameters:
      data - the dictionary content map.
    • MutableDictionary

      public MutableDictionary(@NonNull String json)
      Creates a new MutableDictionary with content from the passed JSON string.
      Parameters:
      json - the dictionary content as a JSON string.
  • Method Details

    • setData

      @NonNull public MutableDictionary setData(@NonNull Map<String,?> data)
      Populate a dictionary 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 dictionary content will replace the current data including any existing Array and Dictionary objects.
      Specified by:
      setData in interface MutableDictionaryInterface
      Parameters:
      data - the dictionary object.
      Returns:
      The self object.
    • setJSON

      @NonNull public MutableDictionary setJSON(@NonNull String json)
      Populate a dictionary with content from a JSON string. Setting the dictionary content will replace the current data including any existing Array and Dictionary objects.
      Specified by:
      setJSON in interface MutableDictionaryInterface
      Parameters:
      json - the dictionary object.
      Returns:
      this Document instance
    • setValue

      @NonNull public MutableDictionary setValue(@NonNull String key, @Nullable Object value)
      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.
      Specified by:
      setValue in interface MutableDictionaryInterface
      Parameters:
      key - the key.
      value - the object value.
      Returns:
      The self object.
    • setString

      @NonNull public MutableDictionary setString(@NonNull String key, @Nullable String value)
      Set a String value for the given key.
      Specified by:
      setString in interface MutableDictionaryInterface
      Parameters:
      key - The key
      value - The String value.
      Returns:
      The self object.
    • setNumber

      @NonNull public MutableDictionary setNumber(@NonNull String key, @Nullable Number value)
      Set a Number value for the given key.
      Specified by:
      setNumber in interface MutableDictionaryInterface
      Parameters:
      key - The key
      value - The number value.
      Returns:
      The self object.
    • setInt

      @NonNull public MutableDictionary setInt(@NonNull String key, int value)
      Set an int value for the given key.
      Specified by:
      setInt in interface MutableDictionaryInterface
      Parameters:
      key - The key
      value - The int value.
      Returns:
      The self object.
    • setLong

      @NonNull public MutableDictionary setLong(@NonNull String key, long value)
      Set a long value for the given key.
      Specified by:
      setLong in interface MutableDictionaryInterface
      Parameters:
      key - The key
      value - The long value.
      Returns:
      The self object.
    • setFloat

      @NonNull public MutableDictionary setFloat(@NonNull String key, float value)
      Set a float value for the given key.
      Specified by:
      setFloat in interface MutableDictionaryInterface
      Parameters:
      key - The key
      value - The float value.
      Returns:
      The self object.
    • setDouble

      @NonNull public MutableDictionary setDouble(@NonNull String key, double value)
      Set a double value for the given key.
      Specified by:
      setDouble in interface MutableDictionaryInterface
      Parameters:
      key - The key
      value - The double value.
      Returns:
      The self object.
    • setBoolean

      @NonNull public MutableDictionary setBoolean(@NonNull String key, boolean value)
      Set a boolean value for the given key.
      Specified by:
      setBoolean in interface MutableDictionaryInterface
      Parameters:
      key - The key
      value - The boolean value.
      Returns:
      The self object.
    • setBlob

      @NonNull public MutableDictionary setBlob(@NonNull String key, @Nullable Blob value)
      Set a Blob object for the given key.
      Specified by:
      setBlob in interface MutableDictionaryInterface
      Parameters:
      key - The key
      value - The Blob object.
      Returns:
      The self object.
    • setDate

      @NonNull public MutableDictionary setDate(@NonNull String key, @Nullable Date value)
      Set a Date object for the given key.
      Specified by:
      setDate in interface MutableDictionaryInterface
      Parameters:
      key - The key
      value - The Date object.
      Returns:
      The self object.
    • setArray

      @NonNull public MutableDictionary setArray(@NonNull String key, @Nullable Array value)
      Set an Array object for the given key.
      Specified by:
      setArray in interface MutableDictionaryInterface
      Parameters:
      key - The key
      value - The Array object.
      Returns:
      The self object.
    • setDictionary

      @NonNull public MutableDictionary setDictionary(@NonNull String key, @Nullable Dictionary value)
      Set a Dictionary object for the given key.
      Specified by:
      setDictionary in interface MutableDictionaryInterface
      Parameters:
      key - The key
      value - The Dictionary object.
      Returns:
      The self object.
    • remove

      @NonNull public MutableDictionary remove(@NonNull String key)
      Removes the mapping for a key from this Dictionary
      Specified by:
      remove in interface MutableDictionaryInterface
      Parameters:
      key - the key.
      Returns:
      The self object.
    • getArray

      @Nullable public MutableArray getArray(@NonNull String key)
      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 interface DictionaryInterface
      Specified by:
      getArray in interface MutableDictionaryInterface
      Overrides:
      getArray in class Dictionary
      Parameters:
      key - the key.
      Returns:
      the Array object.
    • getDictionary

      @Nullable public MutableDictionary 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
      Specified by:
      getDictionary in interface MutableDictionaryInterface
      Overrides:
      getDictionary in class Dictionary
      Parameters:
      key - the key.
      Returns:
      the Dictionary object or null if the key doesn't exist.
    • toJSON

      @NonNull public String toJSON()
      Description copied from class: AbstractJFleeceCollection
      Encode an Array as a JSON string
      Specified by:
      toJSON in interface com.couchbase.lite.internal.fleece.JSONEncodable
      Overrides:
      toJSON in class AbstractJFleeceCollection<com.couchbase.lite.internal.fleece.MDict>
      Returns:
      JSON encoded representation of the Array