- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<JsonElement>
,Collection<JsonElement>
,List<JsonElement>
,RandomAccess
JsonArray is an array of
JsonElement
s. It includes methods for accessing members as various
Java types.- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an emptyJsonArray
with an initial capacity of ten.JsonArray
(int initialCapacity) Constructs an emptyJsonArray
with specified initial capacity.JsonArray
(Collection<? extends JsonElement> jsonElements) Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int index, @Nullable JsonElement element) Appends the specified boolean to the end of thisJsonArray
.Appends the specified double to the end of thisJsonArray
.Appends the specified float to the end of thisJsonArray
.Appends the specified integer to the end of thisJsonArray
.Appends the specified long to the end of thisJsonArray
.Appends the specified string to the end of thisJsonArray
.boolean
add
(@Nullable JsonElement jsonElement) add
(@Nullable JsonObject value) Appends the specifiedJsonObject
to the end of thisJsonArray
.addNull()
AppendsJsonElementType.NULL
to the end of thisJsonArray
.getArray
(int index) boolean
getBoolean
(int index) Returns the boolean at the specified position in thisJsonArray
.double
getDouble
(int index) Returns the double at the specified position in thisJsonArray
.float
getFloat
(int index) Returns the float at the specified position in thisJsonArray
.int
getInt
(int index) Returns the integer at the specified position in thisJsonArray
.long
getLong
(int index) Returns the long at the specified position in thisJsonArray
.getObject
(int index) Returns theJsonObject
at the specified position in thisJsonArray
.getString
(int index) Returns the String at the specified position in thisJsonArray
.boolean
isNull
(int index) Returns true if theJsonElement
at the specified position in thisJsonArray
as of typeJsonElementType.NULL
.toString()
Formats thisJsonArray
as a string with no indentation.toString
(int spaces) Formats thisJsonArray
as a string with specified number of spaces for indentation.Methods inherited from class java.util.ArrayList
addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
Methods inherited from class java.util.AbstractCollection
containsAll
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods inherited from interface java.util.List
containsAll
-
Constructor Details
-
JsonArray
public JsonArray()Constructs an emptyJsonArray
with an initial capacity of ten. -
JsonArray
public JsonArray(int initialCapacity) Constructs an emptyJsonArray
with specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the list- Throws:
IllegalArgumentException
- if specified initial capacity is negative
-
JsonArray
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.- Parameters:
jsonElements
- the collection whose elements are to be placed into this list- Throws:
NullPointerException
- – if the specified collection is null
-
-
Method Details
-
getObject
Returns theJsonObject
at the specified position in thisJsonArray
.- Parameters:
index
- the index of theJsonObject
to return- Returns:
- the
JsonObject
at specified index - Throws:
JsonElementTypeException
- ifJsonElement
at index is not of typeJsonElementType.JSON_OBJECT
-
getArray
- Parameters:
index
- the index of theJsonArray
to return- Returns:
- the
JsonArray
at specified index - Throws:
JsonElementTypeException
- ifJsonElement
at index is not of typeJsonElementType.JSON_ARRAY
-
getString
Returns the String at the specified position in thisJsonArray
.- Parameters:
index
- the index of the String to return- Returns:
- the String at specified index
- Throws:
JsonElementTypeException
- ifJsonElement
at index is not of typeJsonElementType.STRING
-
getInt
public int getInt(int index) Returns the integer at the specified position in thisJsonArray
.- Parameters:
index
- the index of the integer to return- Returns:
- the integer at specified index
- Throws:
JsonElementTypeException
- ifJsonElement
at index is not of typeJsonElementType.LONG
-
getLong
public long getLong(int index) Returns the long at the specified position in thisJsonArray
.- Parameters:
index
- the index of the long to return- Returns:
- the long at specified index
- Throws:
JsonElementTypeException
- ifJsonElement
at index is not of typeJsonElementType.LONG
-
getDouble
public double getDouble(int index) Returns the double at the specified position in thisJsonArray
.- Parameters:
index
- the index of the double to return- Returns:
- the double at specified index
- Throws:
JsonElementTypeException
- ifJsonElement
at index is not of typeJsonElementType.DOUBLE
-
getFloat
public float getFloat(int index) Returns the float at the specified position in thisJsonArray
.- Parameters:
index
- the index of the float to return- Returns:
- the float at specified index
- Throws:
JsonElementTypeException
- ifJsonElement
at index is not of typeJsonElementType.DOUBLE
-
getBoolean
public boolean getBoolean(int index) Returns the boolean at the specified position in thisJsonArray
.- Parameters:
index
- the index of the boolean to return- Returns:
- the boolean at specified index
- Throws:
JsonElementTypeException
- ifJsonElement
at index is not of typeJsonElementType.BOOLEAN
-
isNull
public boolean isNull(int index) Returns true if theJsonElement
at the specified position in thisJsonArray
as of typeJsonElementType.NULL
.- Parameters:
index
- the index to check ifJsonElementType.NULL
- Returns:
- the true if
JsonElementType.NULL
is at specified index
-
add
- Specified by:
add
in interfaceCollection<JsonElement>
- Specified by:
add
in interfaceList<JsonElement>
- Overrides:
add
in classArrayList<JsonElement>
-
add
- Specified by:
add
in interfaceList<JsonElement>
- Overrides:
add
in classArrayList<JsonElement>
-
add
Appends the specifiedJsonObject
to the end of thisJsonArray
. If the specified value isnull
theJsonElementType.NULL
will be appended.- Parameters:
value
- theJsonObject
to append- Returns:
- this
-
add
Appends the specifiedJsonArray
to the end of thisJsonArray
. If the specified value isnull
theJsonElementType.NULL
will be appended.- Parameters:
value
- theJsonArray
to append- Returns:
- this
-
add
Appends the specified string to the end of thisJsonArray
. If the specified value isnull
theJsonElementType.NULL
will be appended.- Parameters:
value
- the string to append- Returns:
- this
-
add
Appends the specified integer to the end of thisJsonArray
. If the specified value isnull
theJsonElementType.NULL
will be appended.- Parameters:
value
- the integer to append- Returns:
- this
-
add
Appends the specified long to the end of thisJsonArray
. If the specified value isnull
theJsonElementType.NULL
will be appended.- Parameters:
value
- the long to append- Returns:
- this
-
add
Appends the specified float to the end of thisJsonArray
. If the specified value isnull
theJsonElementType.NULL
will be appended.- Parameters:
value
- the float to append- Returns:
- this
-
add
Appends the specified double to the end of thisJsonArray
. If the specified value isnull
theJsonElementType.NULL
will be appended.- Parameters:
value
- the double to append- Returns:
- this
-
add
Appends the specified boolean to the end of thisJsonArray
. If the specified value isnull
theJsonElementType.NULL
will be appended.- Parameters:
value
- the boolean to append- Returns:
- this
-
addNull
AppendsJsonElementType.NULL
to the end of thisJsonArray
.- Returns:
- this
-
toString
Formats thisJsonArray
as a string with no indentation.- Overrides:
toString
in classAbstractCollection<JsonElement>
- Returns:
- formatted JSON string
-
toString
Formats thisJsonArray
as a string with specified number of spaces for indentation.- Parameters:
spaces
- the spaces for each indentation- Returns:
- formatted JSON string with spaces for indentation
-