Class Array

    • Field Detail

      • lock

        @NonNull
        protected final Object lock
      • internalArray

        @NonNull
        protected final com.couchbase.lite.internal.fleece.MArray internalArray
    • Constructor Detail

      • Array

        protected Array()
      • Array

        protected Array​(@NonNull
                        com.couchbase.lite.internal.fleece.MArray array)
    • Method Detail

      • toMutable

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

        public final int count()
        Gets a number of the items in the array.
        Specified by:
        count in interface ArrayInterface
        Returns:
        the size of the array
      • getValue

        @Nullable
        public Object getValue​(int index)
        Gets value at the given index as an object. The object types are Blob, Array, Dictionary, Number, or String based on the underlying data type; or null if the value is nil.
        Specified by:
        getValue in interface ArrayInterface
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the Object or null.
      • getString

        @Nullable
        public String getString​(int index)
        Gets value at the given index as a String. Returns null if the value doesn't exist, or its value is not a String.
        Specified by:
        getString in interface ArrayInterface
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the String or null.
      • getNumber

        @Nullable
        public Number getNumber​(int index)
        Gets value at the given index as a Number. Returns null if the value doesn't exist, or its value is not a Number.
        Specified by:
        getNumber in interface ArrayInterface
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the Number or nil.
      • getInt

        public int getInt​(int index)
        Gets value at the given index 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 ArrayInterface
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the int value.
      • getLong

        public long getLong​(int index)
        Gets value at the given index 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 ArrayInterface
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the long value.
      • getFloat

        public float getFloat​(int index)
        Gets value at the given index 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 ArrayInterface
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the float value.
      • getDouble

        public double getDouble​(int index)
        Gets value at the given index 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 ArrayInterface
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the double value.
      • getBoolean

        public boolean getBoolean​(int index)
        Gets value at the given index as a boolean.
        Specified by:
        getBoolean in interface ArrayInterface
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the boolean value.
      • getBlob

        @Nullable
        public Blob getBlob​(int index)
        Gets value at the given index as a Blob. Returns null if the value doesn't exist, or its value is not a Blob.
        Specified by:
        getBlob in interface ArrayInterface
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the Blob value or null.
      • getDate

        @Nullable
        public Date getDate​(int index)
        Gets value at the given index 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 ArrayInterface
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the Date value or null.
      • getArray

        @Nullable
        public Array getArray​(int index)
        Gets value at the given index as an Array. Returns null if the value doesn't exist, or its value is not an Array.
        Specified by:
        getArray in interface ArrayInterface
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the Array object.
      • getDictionary

        @Nullable
        public Dictionary 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
        Parameters:
        index - the index. This value must not exceed the bounds of the array.
        Returns:
        the Dictionary object.
      • toList

        @NonNull
        public List<Object> toList()
        Gets content of the current object as an List. The values contained in the returned List object are all JSON based values.
        Specified by:
        toList in interface ArrayInterface
        Returns:
        the List object representing the content of the current object in the JSON format.
      • iterator

        @NonNull
        public Iterator<Object> iterator()
        An iterator over elements of this array. A call to the next() method of the returned iterator will throw a ConcurrentModificationException, if the MutableArray is modified while it is in use.
        Specified by:
        iterator in interface Iterable<Object>
        Returns:
        an iterator over the array's elements.
      • 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