Package com.couchbase.lite
Class Array
java.lang.Object
com.couchbase.lite.Array
- All Implemented Interfaces:
ArrayInterface
,com.couchbase.lite.internal.fleece.FLEncodable
,Iterable<Object>
- Direct Known Subclasses:
MutableArray
public class Array
extends Object
implements ArrayInterface, com.couchbase.lite.internal.fleece.FLEncodable, Iterable<Object>
Array provides readonly access to array data.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final com.couchbase.lite.internal.fleece.MArray
protected final Object
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal int
count()
Gets a number of the items in the array.void
encodeTo
(com.couchbase.lite.internal.fleece.FLEncoder enc) boolean
getArray
(int index) Gets value at the given index as an Array.getBlob
(int index) Gets value at the given index as a Blob.boolean
getBoolean
(int index) Gets value at the given index as a boolean.getDate
(int index) Gets value at the given index as a Date.getDictionary
(int index) Gets a Dictionary at the given index.double
getDouble
(int index) Gets value at the given index as an double.float
getFloat
(int index) Gets value at the given index as an float.int
getInt
(int index) Gets value at the given index as an int.long
getLong
(int index) Gets value at the given index as an long.getNumber
(int index) Gets value at the given index as a Number.getString
(int index) Gets value at the given index as a String.getValue
(int index) Gets value at the given index as an object.int
hashCode()
iterator()
An iterator over elements of this array.toJSON()
Encode an Array as a JSON stringtoList()
Gets content of the current object as an List.Return a mutable copy of the arraytoString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
lock
-
internalArray
@NonNull protected final com.couchbase.lite.internal.fleece.MArray internalArray
-
-
Constructor Details
-
Array
protected Array() -
Array
protected Array(@NonNull com.couchbase.lite.internal.fleece.MArray array)
-
-
Method Details
-
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 interfaceArrayInterface
- Returns:
- the size of the array
-
getValue
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 interfaceArrayInterface
- Parameters:
index
- the index. This value must not exceed the bounds of the array.- Returns:
- the Object or null.
-
getString
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 interfaceArrayInterface
- Parameters:
index
- the index. This value must not exceed the bounds of the array.- Returns:
- the String or null.
-
getNumber
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 interfaceArrayInterface
- 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 interfaceArrayInterface
- 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 interfaceArrayInterface
- 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 interfaceArrayInterface
- 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 interfaceArrayInterface
- 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 interfaceArrayInterface
- Parameters:
index
- the index. This value must not exceed the bounds of the array.- Returns:
- the boolean value.
-
getBlob
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 interfaceArrayInterface
- Parameters:
index
- the index. This value must not exceed the bounds of the array.- Returns:
- the Blob value or null.
-
getDate
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 interfaceArrayInterface
- Parameters:
index
- the index. This value must not exceed the bounds of the array.- Returns:
- the Date value or null.
-
getArray
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 interfaceArrayInterface
- Parameters:
index
- the index. This value must not exceed the bounds of the array.- Returns:
- the Array object.
-
getDictionary
Gets a Dictionary at the given index. Return null if the value is not an dictionary.- Specified by:
getDictionary
in interfaceArrayInterface
- Parameters:
index
- the index. This value must not exceed the bounds of the array.- Returns:
- the Dictionary 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 interfaceArrayInterface
- Returns:
- the List object representing the content of the current object in the JSON format.
-
toJSON
Encode an Array as a JSON string- Specified by:
toJSON
in interfaceArrayInterface
- Returns:
- JSON encoded representation of the Array
- Throws:
CouchbaseLiteException
- on encoder failure.
-
iterator
An iterator over elements of this array. A call to thenext()
method of the returned iterator will throw a ConcurrentModificationException, if the MutableArray is modified while it is in use. -
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 interfacecom.couchbase.lite.internal.fleece.FLEncodable
-
equals
-
hashCode
public int hashCode() -
toString
-