Package com.couchbase.lite
Class Array
- java.lang.Object
-
- com.couchbase.lite.Array
-
- All Implemented Interfaces:
com.couchbase.lite.internal.fleece.FLEncodable
,java.lang.Iterable<java.lang.Object>
- Direct Known Subclasses:
MutableArray
public class Array extends java.lang.Object implements com.couchbase.lite.internal.fleece.FLEncodable, java.lang.Iterable<java.lang.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(com.couchbase.lite.internal.fleece.FLEncoder enc)
encodeTo(FlEncoder) is internal method.boolean
equals(java.lang.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.java.util.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.java.lang.Number
getNumber(int index)
Gets value at the given index as a Number.java.lang.String
getString(int index)
Gets value at the given index as a String.java.lang.Object
getValue(int index)
Gets value at the given index as an object.int
hashCode()
java.util.Iterator<java.lang.Object>
iterator()
java.lang.String
toJSON()
java.util.List<java.lang.Object>
toList()
Gets content of the current object as an List.MutableArray
toMutable()
Return a mutable copy of the 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.- Returns:
- the size of the array
-
getValue
@Nullable public java.lang.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 java.lang.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 java.lang.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 java.util.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 java.util.List<java.lang.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 java.lang.String toJSON()
-
iterator
@NonNull public java.util.Iterator<java.lang.Object> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.Object>
-
encodeTo
public void encodeTo(@NonNull com.couchbase.lite.internal.fleece.FLEncoder enc)
encodeTo(FlEncoder) is internal method. Please don't use this method.- Specified by:
encodeTo
in interfacecom.couchbase.lite.internal.fleece.FLEncodable
-
equals
public boolean equals(@Nullable java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-