public final class JsonArray extends JsonElement implements java.util.List<JsonElement>, Freezable<JsonArray>
JsonObjects, other JsonArrays, Strings,
Booleans, Integers, Longs, Doubles, null or JsonNull.
Values may not be NaNs, infinities, or of any type not listed here.
JsonArray has the same type coercion behavior and
optional/mandatory accessors as JsonObject. See that class'
documentation for details.
Warning: this class represents null in two incompatible
ways: the standard Java null reference, and the sentinel value JsonNull. In particular, get fails if the requested index
holds the null reference, but succeeds if it holds JsonNull.
Instances of this class are not thread safe.
| Constructor and Description |
|---|
JsonArray()
Creates a
JsonArray with no values. |
JsonArray(java.util.Collection copyFrom)
Creates a new
JsonArray by copying all values from the given
collection. |
JsonArray(java.lang.Object array)
Creates a new
JsonArray with values from the given primitive array. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(int i,
JsonElement jsonElement) |
boolean |
add(JsonElement jsonElement) |
boolean |
addAll(java.util.Collection<? extends JsonElement> jsonElements) |
boolean |
addAll(int i,
java.util.Collection<? extends JsonElement> jsonElements) |
JsonArray |
asJsonArray() |
void |
checkIfFrozen() |
void |
clear() |
JsonArray |
cloneAsThawed()
Provides for the clone operation.
|
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> objects) |
boolean |
equals(java.lang.Object o) |
JsonArray |
freeze()
Freezes the object.
|
JsonElement |
get(int index)
Returns the value at
index. |
java.lang.Boolean |
getBoolean(int index) |
java.lang.Boolean |
getBoolean(int index,
boolean strict)
Returns the value at
index if it exists and is a boolean or can
be coerced to a boolean. |
java.lang.Double |
getDouble(int index) |
java.lang.Double |
getDouble(int index,
boolean strict)
Returns the value at
index if it exists and is a double or can
be coerced to a double. |
java.lang.Integer |
getInt(int index)
Returns the value at
index if it exists and is an int or
can be coerced to an int. |
java.lang.Integer |
getInt(int index,
boolean strict)
Returns the value at
index if it exists and is an int or
can be coerced to an int. |
JsonArray |
getJsonArray(int index)
Returns the value at
index if it exists and is a JsonArray. |
JsonObject |
getJsonObject(int index)
Returns the value at
index if it exists and is a JsonObject. |
java.lang.String |
getJsonType() |
java.lang.Long |
getLong(int index) |
java.lang.Long |
getLong(int index,
boolean strict)
Returns the value at
index if it exists and is a long or
can be coerced to a long. |
java.lang.String |
getString(int index) |
java.lang.String |
getString(int index,
boolean strict)
Returns the value at
index if it exists, coercing it if
necessary. |
int |
hashCode() |
int |
indexOf(java.lang.Object o) |
boolean |
isEmpty() |
boolean |
isFrozen()
Determines whether the object has been frozen or not.
|
boolean |
isJsonArray() |
boolean |
isNull(int index)
Returns true if this array has no value at
index, or if its value
is the null reference . |
boolean |
isOnlyArrays() |
boolean |
isOnlyBooleans() |
boolean |
isOnlyNumbers() |
boolean |
isOnlyObjects() |
boolean |
isOnlyStrings() |
java.util.Iterator<JsonElement> |
iterator() |
int |
lastIndexOf(java.lang.Object o) |
int |
length()
Returns the number of values in this array.
|
java.util.ListIterator<JsonElement> |
listIterator() |
java.util.ListIterator<JsonElement> |
listIterator(int i) |
JsonElement |
opt(int index)
Returns the value at
index, or null if the array has no value
at index. |
java.lang.Boolean |
optBoolean(int index)
Returns the value at
index if it exists and is a boolean or can
be coerced to a boolean. |
java.lang.Boolean |
optBoolean(int index,
java.lang.Boolean fallback)
Returns the value at
index if it exists and is a boolean or can
be coerced to a boolean. |
java.lang.Boolean |
optBoolean(int index,
java.lang.Boolean fallback,
boolean strict) |
java.lang.Double |
optDouble(int index)
Returns the value at
index if it exists and is a double or can
be coerced to a double. |
java.lang.Double |
optDouble(int index,
java.lang.Double fallback)
Returns the value at
index if it exists and is a double or can
be coerced to a double. |
java.lang.Double |
optDouble(int index,
java.lang.Double fallback,
boolean strict) |
java.lang.Integer |
optInt(int index) |
java.lang.Integer |
optInt(int index,
java.lang.Integer fallback)
Returns the value at
index if it exists and is an int or
can be coerced to an int. |
java.lang.Integer |
optInt(int index,
java.lang.Integer fallback,
boolean strict) |
JsonArray |
optJsonArray(int index)
Returns the value at
index if it exists and is a JsonArray. |
JsonObject |
optJsonObject(int index)
Returns the value at
index if it exists and is a JsonObject. |
java.lang.Long |
optLong(int index)
Returns the value at
index if it exists and is a long or
can be coerced to a long. |
java.lang.Long |
optLong(int index,
java.lang.Long fallback)
Returns the value at
index if it exists and is a long or
can be coerced to a long. |
java.lang.Long |
optLong(int index,
java.lang.Long fallback,
boolean strict) |
java.lang.String |
optString(int index)
Returns the value at
index if it exists, coercing it if
necessary. |
java.lang.String |
optString(int index,
java.lang.String fallback)
Returns the value at
index if it exists, coercing it if
necessary. |
java.lang.String |
optString(int index,
java.lang.String fallback,
boolean strict) |
JsonArray |
put(boolean value)
Appends
value to the end of this array. |
JsonArray |
put(double value)
Appends
value to the end of this array. |
JsonArray |
put(int value)
Appends
value to the end of this array. |
JsonArray |
put(int index,
boolean value)
Sets the value at
index to value, null padding this array
to the required length if necessary. |
JsonArray |
put(int index,
double value)
Sets the value at
index to value, null padding this array
to the required length if necessary. |
JsonArray |
put(int index,
int value)
Sets the value at
index to value, null padding this array
to the required length if necessary. |
JsonArray |
put(int index,
long value)
Sets the value at
index to value, null padding this array
to the required length if necessary. |
JsonArray |
put(int index,
java.lang.Object value)
Sets the value at
index to value, null padding this array
to the required length if necessary. |
JsonArray |
put(JsonElement value) |
JsonArray |
put(long value)
Appends
value to the end of this array. |
JsonArray |
put(java.lang.Object value)
Appends
value to the end of this array. |
JsonElement |
remove(int index)
Removes and returns the value at
index, or null if the array has no value
at index. |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> objects) |
boolean |
retainAll(java.util.Collection<?> objects) |
JsonElement |
set(int i,
JsonElement jsonElement) |
int |
size() |
java.util.List<JsonElement> |
subList(int i,
int i2) |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] ts) |
java.util.ArrayList<java.lang.String> |
toArrayList() |
JsonObject |
toJsonObject(JsonArray names)
Returns a new object whose values are the values in this array, and whose
names are the values in
names. |
void |
write(JsonWriter writer) |
public JsonArray()
JsonArray with no values.public JsonArray(java.util.Collection copyFrom)
throws JsonException
JsonArray by copying all values from the given
collection.copyFrom - a collection whose values are of supported types.
Unsupported values are not permitted and will yield an array in an
inconsistent state.JsonExceptionpublic JsonArray(java.lang.Object array)
throws JsonException
JsonArray with values from the given primitive array.JsonExceptionpublic int length()
public JsonArray put(boolean value)
value to the end of this array.public JsonArray put(double value) throws JsonException
value to the end of this array.value - a finite value. May not be NaNs or
infinities.JsonExceptionpublic JsonArray put(int value)
value to the end of this array.public JsonArray put(long value)
value to the end of this array.public JsonArray put(java.lang.Object value) throws JsonException
value to the end of this array.value - a JsonObject, JsonArray, String, Boolean,
Integer, Long, Double, or null. May
not be NaNs or infinities. Unsupported values are not permitted and will cause the
array to be in an inconsistent state.JsonExceptionpublic JsonArray put(JsonElement value)
public JsonArray put(int index, boolean value) throws JsonException
index to value, null padding this array
to the required length if necessary. If a value already exists at index, it will be replaced.JsonExceptionpublic JsonArray put(int index, double value) throws JsonException
index to value, null padding this array
to the required length if necessary. If a value already exists at index, it will be replaced.value - a finite value. May not be NaNs or
infinities.JsonExceptionpublic JsonArray put(int index, int value) throws JsonException
index to value, null padding this array
to the required length if necessary. If a value already exists at index, it will be replaced.JsonExceptionpublic JsonArray put(int index, long value) throws JsonException
index to value, null padding this array
to the required length if necessary. If a value already exists at index, it will be replaced.JsonExceptionpublic JsonArray put(int index, java.lang.Object value) throws JsonException
index to value, null padding this array
to the required length if necessary. If a value already exists at index, it will be replaced.value - a JsonObject, JsonArray, String, Boolean,
Integer, Long, Double, or null. May
not be NaNs or infinities.JsonExceptionpublic boolean isNull(int index)
index, or if its value
is the null reference .public JsonElement get(int index) throws JsonException
index.get in interface java.util.List<JsonElement>JsonException - if this array has no value at index, or if
that value is the null reference. This method returns
normally if the value is JsonObject#NULL.public JsonElement set(int i, JsonElement jsonElement)
set in interface java.util.List<JsonElement>public void add(int i,
JsonElement jsonElement)
add in interface java.util.List<JsonElement>public JsonElement opt(int index)
index, or null if the array has no value
at index.public JsonElement remove(int index)
index, or null if the array has no value
at index.remove in interface java.util.List<JsonElement>public int indexOf(java.lang.Object o)
indexOf in interface java.util.List<JsonElement>public int lastIndexOf(java.lang.Object o)
lastIndexOf in interface java.util.List<JsonElement>public java.util.ListIterator<JsonElement> listIterator()
listIterator in interface java.util.List<JsonElement>public java.util.ListIterator<JsonElement> listIterator(int i)
listIterator in interface java.util.List<JsonElement>public java.util.List<JsonElement> subList(int i, int i2)
subList in interface java.util.List<JsonElement>public java.lang.Boolean getBoolean(int index,
boolean strict)
throws JsonException
index if it exists and is a boolean or can
be coerced to a boolean.JsonException - if the value at index doesn't exist or
cannot be coerced to a boolean.public java.lang.Boolean getBoolean(int index)
throws JsonException
JsonExceptionpublic java.lang.Boolean optBoolean(int index)
index if it exists and is a boolean or can
be coerced to a boolean. Returns false otherwise.public java.lang.Boolean optBoolean(int index,
java.lang.Boolean fallback)
index if it exists and is a boolean or can
be coerced to a boolean. Returns fallback otherwise.public java.lang.Boolean optBoolean(int index,
java.lang.Boolean fallback,
boolean strict)
public java.lang.Double getDouble(int index,
boolean strict)
throws JsonException
index if it exists and is a double or can
be coerced to a double.JsonException - if the value at index doesn't exist or
cannot be coerced to a double.public java.lang.Double getDouble(int index)
throws JsonException
JsonExceptionpublic java.lang.Double optDouble(int index)
index if it exists and is a double or can
be coerced to a double. Returns NaN otherwise.public java.lang.Double optDouble(int index,
java.lang.Double fallback)
index if it exists and is a double or can
be coerced to a double. Returns fallback otherwise.public java.lang.Double optDouble(int index,
java.lang.Double fallback,
boolean strict)
public java.lang.Integer getInt(int index)
throws JsonException
index if it exists and is an int or
can be coerced to an int.JsonException - if the value at index doesn't exist or
cannot be coerced to a int.public java.lang.Integer getInt(int index,
boolean strict)
throws JsonException
index if it exists and is an int or
can be coerced to an int. Returns 0 otherwise.JsonExceptionpublic java.lang.Integer optInt(int index)
public java.lang.Integer optInt(int index,
java.lang.Integer fallback)
index if it exists and is an int or
can be coerced to an int. Returns fallback otherwise.public java.lang.Integer optInt(int index,
java.lang.Integer fallback,
boolean strict)
public java.lang.Long getLong(int index,
boolean strict)
throws JsonException
index if it exists and is a long or
can be coerced to a long.JsonException - if the value at index doesn't exist or
cannot be coerced to a long.public java.lang.Long getLong(int index)
throws JsonException
JsonExceptionpublic java.lang.Long optLong(int index)
index if it exists and is a long or
can be coerced to a long. Returns 0 otherwise.public java.lang.Long optLong(int index,
java.lang.Long fallback)
index if it exists and is a long or
can be coerced to a long. Returns fallback otherwise.public java.lang.Long optLong(int index,
java.lang.Long fallback,
boolean strict)
public java.lang.String getString(int index,
boolean strict)
throws JsonException
index if it exists, coercing it if
necessary.JsonException - if no such value exists.public java.lang.String getString(int index)
throws JsonException
JsonExceptionpublic java.lang.String optString(int index)
index if it exists, coercing it if
necessary. Returns the empty string if no such value exists.public java.lang.String optString(int index,
java.lang.String fallback)
index if it exists, coercing it if
necessary. Returns fallback if no such value exists.public java.lang.String optString(int index,
java.lang.String fallback,
boolean strict)
public JsonArray getJsonArray(int index) throws JsonException
index if it exists and is a JsonArray.JsonException - if the value doesn't exist or is not a JsonArray.public JsonArray optJsonArray(int index)
index if it exists and is a JsonArray. Returns null otherwise.public JsonObject getJsonObject(int index) throws JsonException
index if it exists and is a JsonObject.JsonException - if the value doesn't exist or is not a JsonObject.public JsonObject optJsonObject(int index)
index if it exists and is a JsonObject. Returns null otherwise.public JsonObject toJsonObject(JsonArray names) throws JsonException
names. Names and values are paired up by
index from 0 through to the shorter array's length. Names that are not
strings will be coerced to strings. This method returns null if either
array is empty.JsonExceptionpublic java.util.ArrayList<java.lang.String> toArrayList()
public boolean isOnlyStrings()
public boolean isOnlyNumbers()
public boolean isOnlyBooleans()
public boolean isOnlyObjects()
public boolean isOnlyArrays()
public void write(JsonWriter writer) throws java.io.IOException
write in class JsonElementjava.io.IOExceptionpublic boolean isJsonArray()
isJsonArray in class JsonElementpublic JsonArray asJsonArray()
asJsonArray in class JsonElementpublic boolean equals(java.lang.Object o)
equals in interface java.util.Collection<JsonElement>equals in interface java.util.List<JsonElement>equals in class JsonElementpublic int hashCode()
hashCode in interface java.util.Collection<JsonElement>hashCode in interface java.util.List<JsonElement>hashCode in class JsonElementpublic int size()
size in interface java.util.Collection<JsonElement>size in interface java.util.List<JsonElement>public boolean isEmpty()
isEmpty in interface java.util.Collection<JsonElement>isEmpty in interface java.util.List<JsonElement>public boolean contains(java.lang.Object o)
contains in interface java.util.Collection<JsonElement>contains in interface java.util.List<JsonElement>public java.util.Iterator<JsonElement> iterator()
iterator in interface java.lang.Iterable<JsonElement>iterator in interface java.util.Collection<JsonElement>iterator in interface java.util.List<JsonElement>public java.lang.Object[] toArray()
toArray in interface java.util.Collection<JsonElement>toArray in interface java.util.List<JsonElement>public <T> T[] toArray(T[] ts)
toArray in interface java.util.Collection<JsonElement>toArray in interface java.util.List<JsonElement>public boolean add(JsonElement jsonElement)
add in interface java.util.Collection<JsonElement>add in interface java.util.List<JsonElement>public boolean remove(java.lang.Object o)
remove in interface java.util.Collection<JsonElement>remove in interface java.util.List<JsonElement>public boolean containsAll(java.util.Collection<?> objects)
containsAll in interface java.util.Collection<JsonElement>containsAll in interface java.util.List<JsonElement>public boolean addAll(java.util.Collection<? extends JsonElement> jsonElements)
addAll in interface java.util.Collection<JsonElement>addAll in interface java.util.List<JsonElement>public boolean addAll(int i,
java.util.Collection<? extends JsonElement> jsonElements)
addAll in interface java.util.List<JsonElement>public boolean removeAll(java.util.Collection<?> objects)
removeAll in interface java.util.Collection<JsonElement>removeAll in interface java.util.List<JsonElement>public boolean retainAll(java.util.Collection<?> objects)
retainAll in interface java.util.Collection<JsonElement>retainAll in interface java.util.List<JsonElement>public void clear()
clear in interface java.util.Collection<JsonElement>clear in interface java.util.List<JsonElement>public java.lang.String getJsonType()
getJsonType in class JsonElementpublic boolean isFrozen()
Freezablepublic JsonArray cloneAsThawed()
FreezablecloneAsThawed in interface Freezable<JsonArray>public void checkIfFrozen()