public class JsonArray extends JsonValue implements java.lang.Iterable<java.lang.Object>
Represents a JSON array that can be stored and loaded from Couchbase Server.
If boxed return values are unboxed, the calling code needs to make sure to handle potential NullPointerException
s.
The JsonArray
is backed by a List
and is intended to work similar to it API wise, but to only allow to store such objects which can be represented by JSON.
Modifier and Type | Method and Description |
---|---|
JsonArray |
add(boolean value)
Append an
Boolean element to the JsonArray . |
JsonArray |
add(double value)
Append an
Double element to the JsonArray . |
JsonArray |
add(int value)
Append an
Integer element to the JsonArray . |
JsonArray |
add(JsonArray value)
|
JsonArray |
add(JsonObject value)
Append an
JsonObject element to the JsonArray . |
JsonArray |
add(long value)
Append an
Long element to the JsonArray . |
JsonArray |
add(java.lang.Object value)
Append an element to the
JsonArray . |
JsonArray |
add(java.lang.String value)
Append an
String element to the JsonArray . |
static JsonArray |
create()
Creates a empty
JsonArray . |
static JsonArray |
empty()
Creates a empty
JsonArray . |
static JsonArray |
from(java.lang.Object... items)
Creates a new
JsonArray and populates it with the values supplied. |
java.lang.Object |
get(int index)
Retrieves the value by the position in the
JsonArray and does not cast it. |
JsonArray |
getArray(int index)
|
boolean |
getBoolean(int index)
Retrieves the value by the position in the
JsonArray and casts it to Boolean . |
java.lang.Double |
getDouble(int index)
Retrieves the value by the position in the
JsonArray and casts it to Double . |
java.lang.Integer |
getInt(int index)
Retrieves the value by the position in the
JsonArray and casts it to Integer . |
java.lang.Long |
getLong(int index)
Retrieves the value by the position in the
JsonArray and casts it to Long . |
JsonObject |
getObject(int index)
Retrieves the value by the position in the
JsonArray and casts it to JsonObject . |
java.lang.String |
getString(int index)
Retrieves the value by the position in the
JsonArray and casts it to String . |
boolean |
isEmpty()
Checks if the
JsonArray is empty or not. |
java.util.Iterator<java.lang.Object> |
iterator() |
int |
size()
Returns the size of the
JsonArray . |
java.util.List<java.lang.Object> |
toList()
Copies the content of the
JsonArray into a new List and return it. |
java.lang.String |
toString()
Converts the
JsonArray into its JSON string representation. |
public static JsonArray from(java.lang.Object... items)
Creates a new JsonArray
and populates it with the values supplied.
If the type is not supported, a IllegalArgumentException
exception is thrown.
public java.lang.Object get(int index)
Retrieves the value by the position in the JsonArray
and does not cast it.
index
- the index of the value.public JsonArray add(java.lang.Object value)
Append an element to the JsonArray
.
Note that the type is checked and a IllegalArgumentException
is thrown if not supported.
value
- the value to append.JsonArray
.public JsonArray add(java.lang.String value)
Append an String
element to the JsonArray
.
value
- the value to append.JsonArray
.public java.lang.String getString(int index)
Retrieves the value by the position in the JsonArray
and casts it to String
.
index
- the index of the value.public JsonArray add(long value)
Append an Long
element to the JsonArray
.
value
- the value to append.JsonArray
.public java.lang.Long getLong(int index)
Retrieves the value by the position in the JsonArray
and casts it to Long
.
index
- the index of the value.public JsonArray add(int value)
Append an Integer
element to the JsonArray
.
value
- the value to append.JsonArray
.public java.lang.Integer getInt(int index)
Retrieves the value by the position in the JsonArray
and casts it to Integer
.
index
- the index of the value.public JsonArray add(double value)
Append an Double
element to the JsonArray
.
value
- the value to append.JsonArray
.public java.lang.Double getDouble(int index)
Retrieves the value by the position in the JsonArray
and casts it to Double
.
index
- the index of the value.public JsonArray add(boolean value)
Append an Boolean
element to the JsonArray
.
value
- the value to append.JsonArray
.public boolean getBoolean(int index)
Retrieves the value by the position in the JsonArray
and casts it to Boolean
.
index
- the index of the value.public JsonArray add(JsonObject value)
Append an JsonObject
element to the JsonArray
.
value
- the value to append.JsonArray
.public JsonObject getObject(int index)
Retrieves the value by the position in the JsonArray
and casts it to JsonObject
.
index
- the index of the value.public JsonArray add(JsonArray value)
value
- the value to append.JsonArray
.public JsonArray getArray(int index)
index
- the index of the value.public java.util.List<java.lang.Object> toList()
Copies the content of the JsonArray
into a new List
and return it.
JsonArray
in a new List
.public boolean isEmpty()
Checks if the JsonArray
is empty or not.
public int size()
Returns the size of the JsonArray
.
public java.util.Iterator<java.lang.Object> iterator()
iterator
in interface java.lang.Iterable<java.lang.Object>