Class MutableArray

java.lang.Object
com.couchbase.lite.Array
com.couchbase.lite.MutableArray
All Implemented Interfaces:
ArrayInterface, com.couchbase.lite.internal.fleece.FLEncodable, Iterable<Object>

public final class MutableArray extends Array
Mutable access to array data.
  • Constructor Details

    • MutableArray

      public MutableArray()
      Construct a new empty Array object.
    • MutableArray

      public MutableArray(@NonNull List<Object> data)
      Creates a new MutableArray with content from the passed List. 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 array content list
    • MutableArray

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

    • setData

      @NonNull public MutableArray setData(@NonNull List<Object> data)
      Populate an array 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 array content will replace the current data including any existing Array and Dictionary objects.
      Parameters:
      data - the array
      Returns:
      The self object
    • setJSON

      @NonNull public MutableArray setJSON(@NonNull String json)
      Populate an array with content from a JSON string. 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 array content will replace the current data including any existing Array and Dictionary objects.
      Parameters:
      json - the dictionary object.
      Returns:
      this Document instance
    • setValue

      @NonNull public MutableArray setValue(int index, @Nullable Object value)
      Set an object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the object
      Returns:
      The self object
    • setString

      @NonNull public MutableArray setString(int index, @Nullable String value)
      Sets an String object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the String object
      Returns:
      The self object
    • setNumber

      @NonNull public MutableArray setNumber(int index, @Nullable Number value)
      Sets an NSNumber object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the Number object
      Returns:
      The self object
    • setInt

      @NonNull public MutableArray setInt(int index, int value)
      Sets an integer value at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the int value
      Returns:
      The self object
    • setLong

      @NonNull public MutableArray setLong(int index, long value)
      Sets an integer value at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the long value
      Returns:
      The self object
    • setFloat

      @NonNull public MutableArray setFloat(int index, float value)
      Sets a float value at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the float value
      Returns:
      The self object
    • setDouble

      @NonNull public MutableArray setDouble(int index, double value)
      Sets a double value at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the double value
      Returns:
      The self object
    • setBoolean

      @NonNull public MutableArray setBoolean(int index, boolean value)
      Sets a boolean value at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the boolean value
      Returns:
      The self object
    • setBlob

      @NonNull public MutableArray setBlob(int index, @Nullable Blob value)
      Sets a Blob object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the Blob object
      Returns:
      The self object
    • setDate

      @NonNull public MutableArray setDate(int index, @Nullable Date value)
      Sets a Date object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the Date object
      Returns:
      The self object
    • setArray

      @NonNull public MutableArray setArray(int index, @Nullable Array value)
      Sets a Array object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the Array object
      Returns:
      The self object
    • setDictionary

      @NonNull public MutableArray setDictionary(int index, @Nullable Dictionary value)
      Sets a Dictionary object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the Dictionary object
      Returns:
      The self object
    • addValue

      @NonNull public MutableArray addValue(@Nullable Object value)
      Adds an object to the end of the array.
      Parameters:
      value - the object
      Returns:
      The self object
    • addString

      @NonNull public MutableArray addString(@Nullable String value)
      Adds a String object to the end of the array.
      Parameters:
      value - the String object
      Returns:
      The self object
    • addNumber

      @NonNull public MutableArray addNumber(@Nullable Number value)
      Adds a Number object to the end of the array.
      Parameters:
      value - the Number object
      Returns:
      The self object
    • addInt

      @NonNull public MutableArray addInt(int value)
      Adds an integer value to the end of the array.
      Parameters:
      value - the int value
      Returns:
      The self object
    • addLong

      @NonNull public MutableArray addLong(long value)
      Adds a long value to the end of the array.
      Parameters:
      value - the long value
      Returns:
      The self object
    • addFloat

      @NonNull public MutableArray addFloat(float value)
      Adds a float value to the end of the array.
      Parameters:
      value - the float value
      Returns:
      The self object
    • addDouble

      @NonNull public MutableArray addDouble(double value)
      Adds a double value to the end of the array.
      Parameters:
      value - the double value
      Returns:
      The self object
    • addBoolean

      @NonNull public MutableArray addBoolean(boolean value)
      Adds a boolean value to the end of the array.
      Parameters:
      value - the boolean value
      Returns:
      The self object
    • addBlob

      @NonNull public MutableArray addBlob(@Nullable Blob value)
      Adds a Blob object to the end of the array.
      Parameters:
      value - the Blob object
      Returns:
      The self object
    • addDate

      @NonNull public MutableArray addDate(@Nullable Date value)
      Adds a Date object to the end of the array.
      Parameters:
      value - the Date object
      Returns:
      The self object
    • addArray

      @NonNull public MutableArray addArray(@Nullable Array value)
      Adds an Array object to the end of the array.
      Parameters:
      value - the Array object
      Returns:
      The self object
    • addDictionary

      @NonNull public MutableArray addDictionary(@Nullable Dictionary value)
      Adds a Dictionary object to the end of the array.
      Parameters:
      value - the Dictionary object
      Returns:
      The self object
    • insertValue

      @NonNull public MutableArray insertValue(int index, @Nullable Object value)
      Inserts an object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the object
      Returns:
      The self object
    • insertString

      @NonNull public MutableArray insertString(int index, @Nullable String value)
      Inserts a String object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the String object
      Returns:
      The self object
    • insertNumber

      @NonNull public MutableArray insertNumber(int index, @Nullable Number value)
      Inserts a Number object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the Number object
      Returns:
      The self object
    • insertInt

      @NonNull public MutableArray insertInt(int index, int value)
      Inserts an integer value at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the int value
      Returns:
      The self object
    • insertLong

      @NonNull public MutableArray insertLong(int index, long value)
      Inserts a long value at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the long value
      Returns:
      The self object
    • insertFloat

      @NonNull public MutableArray insertFloat(int index, float value)
      Inserts a float value at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the float value
      Returns:
      The self object
    • insertDouble

      @NonNull public MutableArray insertDouble(int index, double value)
      Inserts a double value at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the double value
      Returns:
      The self object
    • insertBoolean

      @NonNull public MutableArray insertBoolean(int index, boolean value)
      Inserts a boolean value at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the boolean value
      Returns:
      The self object
    • insertBlob

      @NonNull public MutableArray insertBlob(int index, @Nullable Blob value)
      Inserts a Blob object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the Blob object
      Returns:
      The self object
    • insertDate

      @NonNull public MutableArray insertDate(int index, @Nullable Date value)
      Inserts a Date object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the Date object
      Returns:
      The self object
    • insertArray

      @NonNull public MutableArray insertArray(int index, @Nullable Array value)
      Inserts an Array object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the Array object
      Returns:
      The self object
    • insertDictionary

      @NonNull public MutableArray insertDictionary(int index, @Nullable Dictionary value)
      Inserts a Dictionary object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      value - the Dictionary object
      Returns:
      The self object
    • remove

      @NonNull public MutableArray remove(int index)
      Removes the object at the given index.
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      Returns:
      The self object
    • getArray

      @Nullable public MutableArray getArray(int index)
      Gets a Array at the given index. Return null if the value is not an array.
      Specified by:
      getArray in interface ArrayInterface
      Overrides:
      getArray in class Array
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      Returns:
      the Array object.
    • getDictionary

      @Nullable public MutableDictionary getDictionary(int index)
      Gets a Dictionary at the given index. Return null if the value is not an dictionary.
      Specified by:
      getDictionary in interface ArrayInterface
      Overrides:
      getDictionary in class Array
      Parameters:
      index - the index. This value must not exceed the bounds of the array.
      Returns:
      the Dictionary object.
    • toJSON

      @NonNull public String toJSON()
      Specified by:
      toJSON in interface ArrayInterface
      Overrides:
      toJSON in class Array