Package com.couchbase.lite
Class Array
- java.lang.Object
-
- com.couchbase.lite.Array
-
- All Implemented Interfaces:
FLEncodable
,Iterable<Object>
- Direct Known Subclasses:
MutableArray
public class Array extends Object implements FLEncodable, Iterable<Object>
Array provides readonly access to array data.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
count()
Gets a number of the items in the array.void
encodeTo(FLEncoder enc)
encodeTo(FlEncoder) is internal method.boolean
equals(Object o)
Array
getArray(int index)
Gets a Array at the given index.Blob
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.Date
getDate(int index)
Gets value at the given index as a Date.Dictionary
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.Number
getNumber(int index)
Gets value at the given index as a Number.String
getString(int index)
Gets value at the given index as a String.Object
getValue(int index)
Gets value at the given index as an object.int
hashCode()
Iterator<Object>
iterator()
String
toJSON()
List<Object>
toList()
Gets content of the current object as an List.MutableArray
toMutable()
Return a mutable copy of the array-
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
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.- 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 nil if the value is nil.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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 a Array at the given index. Return null if the value is not an array.- 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.- 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.- Returns:
- the List object representing the content of the current object in the JSON format.
-
toJSON
@NonNull public String toJSON()
-
encodeTo
public void encodeTo(@NonNull FLEncoder enc)
encodeTo(FlEncoder) is internal method. Please don't use this method.- Specified by:
encodeTo
in interfaceFLEncodable
-
-