Package org.eclipse.ditto.json
Interface JsonArray
- All Superinterfaces:
Iterable<JsonValue>
,JsonValue
,JsonValueContainer<JsonValue>
Represents a JSON array. A JSON array is an ordered collection of JSON values. Duplicate values are permitted.
Implementations of this interface are required to be immutable!
-
Method Summary
Modifier and TypeMethodDescriptionadd
(boolean value, boolean... furtherValues) Creates a new JSON array by appending the JSON representation of the specified boolean value to the end of this array.add
(double value, double... furtherValues) Creates a new JSON array by appending the JSON representation of the specified double value to the end of this array.add
(int value, int... furtherValues) Creates a new JSON array by appending the JSON representation of the specified int value to the end of this array.add
(long value, long... furtherValues) Creates a new JSON array by appending the JSON representation of the specified long value to the end of this array.Creates a new JSON array by appending the JSON representation of the specified string value to the end of this array.Creates a new JSON array by appending the specified value to the end of this array.boolean
Indicates whether this JSON array contains the specified value.static JsonArray
empty()
Returns an emptyJsonArray
object.get
(int index) Returns the JSON value at the specified position in this array.int
Returns the index of the first occurrence of the specified value in this array, or-1
if this array does not contain the element.static JsonArrayBuilder
Returns a new mutable builder with a fluent API for aJsonArray
.static <T> JsonArray
Returns an instance ofJsonArray
which contains the given values.static JsonArray
Creates a newJsonArray
from the given string.static <T> JsonArray
of
(T value, T... furtherValues) Returns an instance ofJsonArray
which contains the given values.default JsonArrayBuilder
Returns a new mutable builder with a fluent API for aJsonArray
.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods inherited from interface org.eclipse.ditto.json.JsonValue
asArray, asBoolean, asDouble, asInt, asLong, asObject, asString, formatAsString, getUpperBoundForStringSize, isArray, isBoolean, isDouble, isInt, isLong, isNull, isNumber, isObject, isString, toString, writeValue
Methods inherited from interface org.eclipse.ditto.json.JsonValueContainer
getSize, isEmpty, stream
-
Method Details
-
of
Creates a newJsonArray
from the given string.- Parameters:
jsonArrayString
- the string that represents the JSON array.- Returns:
- the JSON array that has been created from the string.
- Throws:
NullPointerException
- ifjsonArrayString
isnull
.IllegalArgumentException
- ifjsonArrayString
is empty.JsonParseException
- ifjsonArrayString
does not represent a valid JSON array.- See Also:
-
empty
Returns an emptyJsonArray
object.- Returns:
- the empty array.
-
of
Returns an instance ofJsonArray
which contains the given values. This method tries to determine the appropriateJsonValue
-counterpart for each given value.- Type Parameters:
T
- the type of values for JsonArray- Parameters:
value
- the mandatory value of the returned JsonArray.furtherValues
- further optional values of the returned JsonArray.- Returns:
- the JsonArray.
- Throws:
NullPointerException
- iffurtherValues
isnull
.JsonParseException
- if eithervalue
or any item offurtherValues
cannot be converted toJsonValue
.
-
of
Returns an instance ofJsonArray
which contains the given values. This method tries to determine the appropriateJsonValue
-counterpart for each item of the specified Iterable.- Type Parameters:
T
- the type of values for JsonArray- Parameters:
values
- the values of the returned JsonArray.null
items are- Returns:
- the JsonArray.
- Throws:
NullPointerException
- ifvalues
isnull
.JsonParseException
- if any item ofvalues
cannot be converted toJsonValue
.
-
newBuilder
Returns a new mutable builder with a fluent API for aJsonArray
.- Returns:
- a new JSON array builder.
-
toBuilder
Returns a new mutable builder with a fluent API for aJsonArray
. The returned builder is already initialised with the data of the this JSON array. This method is useful if an existing JSON array should be strongly modified but the amount of creating objects should be kept low at the same time.- Returns:
- a new JSON array builder with pre-filled data of this JSON array.
-
add
Creates a new JSON array by appending the JSON representation of the specified int value to the end of this array.- Parameters:
value
- the int value to be added to the array.furtherValues
- additional values to be added to the array.- Returns:
- the a new JSON array which differs from this array by containing the specified value at its end.
- Throws:
NullPointerException
- iffurtherValues
isnull
.
-
add
Creates a new JSON array by appending the JSON representation of the specified long value to the end of this array.- Parameters:
value
- the long value to be added to the array.furtherValues
- additional values to be added to the array.- Returns:
- the a new JSON array which differs from this array by containing the specified value at its end.
- Throws:
NullPointerException
- iffurtherValues
isnull
.
-
add
Creates a new JSON array by appending the JSON representation of the specified double value to the end of this array.- Parameters:
value
- the double value to be added to the array.furtherValues
- additional values to be added to the array.- Returns:
- the a new JSON array which differs from this array by containing the specified value at its end.
- Throws:
NullPointerException
- iffurtherValues
isnull
.
-
add
Creates a new JSON array by appending the JSON representation of the specified boolean value to the end of this array.- Parameters:
value
- the boolean value to be added to the array.furtherValues
- additional values to be added to the array.- Returns:
- the a new JSON array which differs from this array by containing the specified value at its end.
- Throws:
NullPointerException
- iffurtherValues
isnull
.
-
add
Creates a new JSON array by appending the JSON representation of the specified string value to the end of this array.- Parameters:
value
- the string to be added to the array.furtherValues
- additional values to be added to the array.- Returns:
- the a new JSON array which differs from this array by containing the specified value at its end.
- Throws:
NullPointerException
- if any argument isnull
.
-
add
Creates a new JSON array by appending the specified value to the end of this array.- Parameters:
value
- the value to be added to the array.furtherValues
- additional values to be added to the array.- Returns:
- the a new JSON array which differs from this array by containing the specified value at its end.
- Throws:
NullPointerException
- if any argument isnull
.
-
get
Returns the JSON value at the specified position in this array.- Parameters:
index
- the index of the array value to be returned. If the index is out of bounds an empty Optional is returned.- Returns:
- the JSON value at the specified position.
-
contains
Indicates whether this JSON array contains the specified value.- Parameters:
value
- the value whose presence in this array is to be tested.- Returns:
true
if this array contains the specified value,false
else.- Throws:
NullPointerException
- ifvalue
isnull
.
-
indexOf
Returns the index of the first occurrence of the specified value in this array, or-1
if this array does not contain the element.- Parameters:
value
- the value to be searched for.- Returns:
- the index of the first occurrence of the specified value in this array, or
-1
if this array does not contain the value at all. - Throws:
NullPointerException
- ifvalue
isnull
.
-