- All Implemented Interfaces:
Serializable,Cloneable,Iterable<JsonElement>,Collection<JsonElement>,List<JsonElement>,RandomAccess
JsonArray is an array of
JsonElements. 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 emptyJsonArraywith an initial capacity of ten.JsonArray(int initialCapacity) Constructs an emptyJsonArraywith 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 TypeMethodDescriptionadd(boolean value) Appends the specified boolean to the end of thisJsonArray.add(double value) Appends the specified double to the end of thisJsonArray.add(float value) Appends the specified float to the end of thisJsonArray.add(int value) Appends the specified integer to the end of thisJsonArray.voidadd(int index, @Nullable JsonElement element) add(long value) Appends the specified long to the end of thisJsonArray.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.booleanadd(@Nullable JsonElement jsonElement) add(@Nullable JsonObject value) Appends the specifiedJsonObjectto the end of thisJsonArray.addNull()AppendsJsonElementType.NULLto the end of thisJsonArray.getArray(int index) @Nullable JsonArraygetArrayOrNull(int index) booleangetBoolean(int index) Returns the boolean at the specified position in thisJsonArray.@Nullable BooleangetBooleanOrNull(int index) Returns the boolean at the specified position in thisJsonArray.doublegetDouble(int index) Returns the double at the specified position in thisJsonArray.@Nullable DoublegetDoubleOrNull(int index) Returns the double at the specified position in thisJsonArray.floatgetFloat(int index) Returns the float at the specified position in thisJsonArray.@Nullable FloatgetFloatOrNull(int index) Returns the float at the specified position in thisJsonArray.intgetInt(int index) Returns the integer at the specified position in thisJsonArray.@Nullable IntegergetIntOrNull(int index) Returns the integer at the specified position in thisJsonArray.longgetLong(int index) Returns the long at the specified position in thisJsonArray.@Nullable LonggetLongOrNull(int index) Returns the long at the specified position in thisJsonArray.getObject(int index) Returns theJsonObjectat the specified position in thisJsonArray.@Nullable JsonObjectgetObjectOrNull(int index) Returns theJsonObjectat the specified position in thisJsonArray.getString(int index) Returns the String at the specified position in thisJsonArray.@Nullable StringgetStringOrNull(int index) Returns the String at the specified position in thisJsonArray.booleanisNull(int index) Returns true if theJsonElementat the specified position in thisJsonArrayas of typeJsonElementType.NULL.toString()Formats thisJsonArrayas a string with no indentation.toString(int spaces) Formats thisJsonArrayas 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, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAllMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll
-
Constructor Details
-
JsonArray
public JsonArray()Constructs an emptyJsonArraywith an initial capacity of ten. -
JsonArray
public JsonArray(int initialCapacity) Constructs an emptyJsonArraywith 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 theJsonObjectat the specified position in thisJsonArray.- Parameters:
index- the index of theJsonObjectto return- Returns:
- the
JsonObjectat specified index - Throws:
JsonElementTypeException- ifJsonElementat index is not of typeJsonElementType.JSON_OBJECT
-
getObjectOrNull
Returns theJsonObjectat the specified position in thisJsonArray. If theJsonElementat index isJsonElementType.NULLthennullis returned.- Parameters:
index- the index of theJsonObjectto return- Returns:
- the
JsonObjectat specified index - Throws:
JsonElementTypeException- ifJsonElementat index is not of typeJsonElementType.JSON_OBJECT
-
getArray
- Parameters:
index- the index of theJsonArrayto return- Returns:
- the
JsonArrayat specified index - Throws:
JsonElementTypeException- ifJsonElementat index is not of typeJsonElementType.JSON_ARRAY
-
getArrayOrNull
Returns theJsonArrayat the specified position in thisJsonArray. If theJsonElementat index isJsonElementType.NULLthennullis returned.- Parameters:
index- the index of theJsonArrayto return- Returns:
- the
JsonArrayat specified index - Throws:
JsonElementTypeException- ifJsonElementat 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- ifJsonElementat index is not of typeJsonElementType.STRING
-
getStringOrNull
Returns the String at the specified position in thisJsonArray. If theJsonElementat index isJsonElementType.NULLthennullis returned.- Parameters:
index- the index of the String to return- Returns:
- the String at specified index or
nullifJsonElementType.NULL - Throws:
JsonElementTypeException- ifJsonElementat 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 the specified index
- Throws:
JsonElementTypeException- ifJsonElementat index is not of typeJsonElementType.LONG
-
getIntOrNull
Returns the integer at the specified position in thisJsonArray. If theJsonElementat index isJsonElementType.NULLthennullis returned.- Parameters:
index- the index of the integer to return- Returns:
- the integer at specified index or
nullifJsonElementType.NULL - Throws:
JsonElementTypeException- ifJsonElementat 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- ifJsonElementat index is not of typeJsonElementType.LONG
-
getLongOrNull
Returns the long at the specified position in thisJsonArray. If theJsonElementat index isJsonElementType.NULLthennullis returned.- Parameters:
index- the index of the long to return- Returns:
- the long at specified index or
nullifJsonElementType.NULL - Throws:
JsonElementTypeException- ifJsonElementat 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- ifJsonElementat index is not of typeJsonElementType.DOUBLE
-
getDoubleOrNull
Returns the double at the specified position in thisJsonArray. If theJsonElementat index isJsonElementType.NULLthennullis returned.- Parameters:
index- the index of the double to return- Returns:
- the double at specified index or
nullifJsonElementType.NULL - Throws:
JsonElementTypeException- ifJsonElementat 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 a specified index
- Throws:
JsonElementTypeException- ifJsonElementat index is not of typeJsonElementType.DOUBLE
-
getFloatOrNull
Returns the float at the specified position in thisJsonArray. If theJsonElementat index isJsonElementType.NULLthennullis returned.- Parameters:
index- the index of the float to return- Returns:
- the float at a specified index or
nullifJsonElementType.NULL - Throws:
JsonElementTypeException- ifJsonElementat 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 a specified index
- Throws:
JsonElementTypeException- ifJsonElementat index is not of typeJsonElementType.BOOLEAN
-
getBooleanOrNull
Returns the boolean at the specified position in thisJsonArray. If theJsonElementat index isJsonElementType.NULLthennullis returned.- Parameters:
index- the index of the boolean to return- Returns:
- the boolean at a specified index or
nullifJsonElementType.NULL - Throws:
JsonElementTypeException- ifJsonElementat index is not of typeJsonElementType.BOOLEAN
-
isNull
public boolean isNull(int index) Returns true if theJsonElementat the specified position in thisJsonArrayas of typeJsonElementType.NULL.- Parameters:
index- the index to check ifJsonElementType.NULL- Returns:
- the true if
JsonElementType.NULLis at specified index
-
add
- Specified by:
addin interfaceCollection<JsonElement>- Specified by:
addin interfaceList<JsonElement>- Overrides:
addin classArrayList<JsonElement>
-
add
- Specified by:
addin interfaceList<JsonElement>- Overrides:
addin classArrayList<JsonElement>
-
add
Appends the specifiedJsonObjectto the end of thisJsonArray. If the specified value isnulltheJsonElementType.NULLwill be appended.- Parameters:
value- theJsonObjectto append- Returns:
- this
-
add
Appends the specifiedJsonArrayto the end of thisJsonArray. If the specified value isnulltheJsonElementType.NULLwill be appended.- Parameters:
value- theJsonArrayto append- Returns:
- this
-
add
Appends the specified string to the end of thisJsonArray. If the specified value isnulltheJsonElementType.NULLwill be appended.- Parameters:
value- the string to append- Returns:
- this
-
add
Appends the specified integer to the end of thisJsonArray.- Parameters:
value- the integer to append- Returns:
- this
-
add
Appends the specified integer to the end of thisJsonArray. If the specified value isnulltheJsonElementType.NULLwill be appended.- Parameters:
value- the integer to append- Returns:
- this
-
add
Appends the specified long to the end of thisJsonArray.- Parameters:
value- the long to append- Returns:
- this
-
add
Appends the specified long to the end of thisJsonArray. If the specified value isnulltheJsonElementType.NULLwill be appended.- Parameters:
value- the long to append- Returns:
- this
-
add
Appends the specified float to the end of thisJsonArray.- Parameters:
value- the float to append- Returns:
- this
-
add
Appends the specified float to the end of thisJsonArray. If the specified value isnulltheJsonElementType.NULLwill be appended.- Parameters:
value- the float to append- Returns:
- this
-
add
Appends the specified double to the end of thisJsonArray.- Parameters:
value- the double to append- Returns:
- this
-
add
Appends the specified double to the end of thisJsonArray. If the specified value isnulltheJsonElementType.NULLwill be appended.- Parameters:
value- the double to append- Returns:
- this
-
add
Appends the specified boolean to the end of thisJsonArray.- Parameters:
value- the boolean to append- Returns:
- this
-
add
Appends the specified boolean to the end of thisJsonArray. If the specified value isnulltheJsonElementType.NULLwill be appended.- Parameters:
value- the boolean to append- Returns:
- this
-
addNull
AppendsJsonElementType.NULLto the end of thisJsonArray.- Returns:
- this
-
toString
Formats thisJsonArrayas a string with no indentation.- Overrides:
toStringin classAbstractCollection<JsonElement>- Returns:
- formatted JSON string
-
toString
Formats thisJsonArrayas a string with specified number of spaces for indentation.- Parameters:
spaces- the spaces for each indentation- Returns:
- formatted JSON string with spaces for indentation
-