Package org.eclipse.ditto.json
Interface JsonArrayBuilder
- All Superinterfaces:
Iterable<JsonValue>
,JsonValueContainer<JsonValue>
A mutable builder with a fluent API for a
JsonArray
. Implementations of this interface are normally not
thread safe and not reusable.-
Method Summary
Modifier and TypeMethodDescriptionadd
(boolean value, boolean... furtherValues) Adds at least one boolean value to the array to be built.add
(double value, double... furtherValues) Adds at least one double value to the JSON array to be built.add
(int value, int... furtherValues) Adds at least new int value to the JSON array to be built.add
(long value, long... furtherValues) Adds at least one long value to the JSON array to be built.Adds at least one string value to the array to be built.Adds at least oneJsonValue
to the array to be built.Adds all given values to the array to be built.addBooleans
(Iterable<Boolean> booleanValues) Adds all given values to the array to be built.addDoubles
(Iterable<Double> doubleValues) Adds all given values to the array to be built.addIntegers
(Iterable<Integer> intValues) Adds all given values to the array to be built.Adds all given values to the array to be built.addStrings
(Iterable<String> stringValues) Adds all given values to the array to be built.build()
Creates a newJsonArray
containing all values which were added beforehand.get
(int index) Returns the JSON value at the specified position in the array to be built.remove
(int index) Removes the value at the specified position from the array to be built.Removes the given value from the array to be built.set
(int index, boolean value) Replaces the value at the specified position in the array to be built.set
(int index, double value) Replaces the value at the specified position in the array to be built.set
(int index, int value) Replaces the value at the specified position in the array to be built.set
(int index, long value) Replaces the value at the specified position in the array to be built.Replaces the value at the specified position in the array to be built.Replaces the value at the specified position in the array to be built.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods inherited from interface org.eclipse.ditto.json.JsonValueContainer
getSize, isEmpty, stream
-
Method Details
-
add
Adds at least new int value to the JSON array to be built.- Parameters:
value
- the int to add to the array.furtherValues
- additional values to be added to the array.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- iffurtherValues
isnull
.
-
addIntegers
Adds all given values to the array to be built.- Parameters:
intValues
- the values to be added.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- ifintValues
isnull
.
-
set
Replaces the value at the specified position in the array to be built.- Parameters:
index
- the position of the element to be set.value
- the value to be placed at the specified position.- Returns:
- this builder to allow method chaining.
- Throws:
IndexOutOfBoundsException
- if the index is out of range, i. e.index < 0 || index > getSize()
-
add
Adds at least one long value to the JSON array to be built.- Parameters:
value
- the long to add to the array.furtherValues
- additional values to be added to the array.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- iffurtherValues
isnull
.
-
addLongs
Adds all given values to the array to be built.- Parameters:
longValues
- the values to be added.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- iflongValues
isnull
.
-
set
Replaces the value at the specified position in the array to be built.- Parameters:
index
- the position of the element to be set.value
- the value to be placed at the specified position.- Returns:
- this builder to allow method chaining.
- Throws:
IndexOutOfBoundsException
- if the index is out of range, i. e.index < 0 || index > getSize()
-
add
Adds at least one double value to the JSON array to be built.- Parameters:
value
- the double to add to the array.furtherValues
- additional values to be added to the array.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- iffurtherValues
isnull
.
-
addDoubles
Adds all given values to the array to be built.- Parameters:
doubleValues
- the values to be added.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- ifdoubleValues
isnull
.
-
set
Replaces the value at the specified position in the array to be built.- Parameters:
index
- the position of the element to be set.value
- the value to be placed at the specified position.- Returns:
- this builder to allow method chaining.
- Throws:
IndexOutOfBoundsException
- if the index is out of range, i. e.index < 0 || index > getSize()
-
add
Adds at least one boolean value to the array to be built.- Parameters:
value
- the boolean to add to the array.furtherValues
- additional values to be added to the array.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- iffurtherValues
isnull
.
-
addBooleans
Adds all given values to the array to be built.- Parameters:
booleanValues
- the values to be added.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- ifbooleanValues
isnull
.
-
set
Replaces the value at the specified position in the array to be built.- Parameters:
index
- the position of the element to be set.value
- the value to be placed at the specified position.- Returns:
- this builder to allow method chaining.
- Throws:
IndexOutOfBoundsException
- if the index is out of range, i. e.index < 0 || index > getSize()
-
add
Adds at least one string value to the array to be built.- Parameters:
value
- the string to add to the array.furtherValues
- additional values to be added to the array.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- if any argument isnull
.
-
addStrings
Adds all given values to the array to be built.- Parameters:
stringValues
- the values to be added.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- ifstringValues
isnull
.
-
set
Replaces the value at the specified position in the array to be built.- Parameters:
index
- the position of the element to be set.value
- the value to be placed at the specified position.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- ifvalue
isnull
.IndexOutOfBoundsException
- if the index is out of range, i. e.index < 0 || index > getSize()
-
add
Adds at least oneJsonValue
to the array to be built.- Parameters:
value
- the JSON value to add to the array.furtherValues
- additional values to be added to the array.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- if any argument isnull
.
-
addAll
Adds all given values to the array to be built.- Parameters:
values
- the values to add to the array.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- ifvalues
isnull
.
-
set
Replaces the value at the specified position in the array to be built.- Parameters:
index
- the position of the element to be set.value
- the value to be placed at the specified position.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- ifvalue
isnull
.IndexOutOfBoundsException
- if the index is out of range, i. e.index < 0 || index > getSize()
-
get
Returns the JSON value at the specified position in the array to be built.- 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.
-
remove
Removes the value at the specified position from the array to be built. This shifts any subsequent values to the left (lowers their indices by one).- Parameters:
index
- the index of the value to be removed.- Returns:
- this builder to allow method chaining.
- Throws:
IndexOutOfBoundsException
- if the index is out of range, i. e.index < 0 || index > getSize()
-
remove
Removes the given value from the array to be built.- Parameters:
value
- the value to be removed.- Returns:
- this builder to allow method chaining.
- Throws:
NullPointerException
- ifvalue
isnull
.
-
build
JsonArray build()Creates a newJsonArray
containing all values which were added beforehand.- Returns:
- a new JSON array.
-