@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class JSONArray extends JSONValue
toString()
method (or
appended to the buffer provided to the toString(StringBuilder)
method) will include one space before each value in the array and one space
before the closing square bracket. There will not be any space between a
value and the comma that follows it. The string representation of each value
in the array will be obtained using that value's toString
method.
toNormalizedString
method.Modifier and Type | Field and Description |
---|---|
static JSONArray |
EMPTY_ARRAY
A pre-allocated empty JSON array.
|
Constructor and Description |
---|
JSONArray(JSONValue... values)
Creates a new JSON array with the provided values.
|
JSONArray(java.util.List<? extends JSONValue> values)
Creates a new JSON array with the provided values.
|
Modifier and Type | Method and Description |
---|---|
void |
appendToJSONBuffer(JSONBuffer buffer)
Appends this value to the provided JSON buffer.
|
void |
appendToJSONBuffer(java.lang.String fieldName,
JSONBuffer buffer)
Appends a field with the given name and this value to the provided JSON
buffer.
|
boolean |
contains(JSONValue value,
boolean ignoreFieldNameCase,
boolean ignoreValueCase,
boolean ignoreArrayOrder,
boolean recursive)
Indicates whether this JSON array contains an element with the specified
value.
|
boolean |
equals(JSONArray array,
boolean ignoreFieldNameCase,
boolean ignoreValueCase,
boolean ignoreArrayOrder)
Indicates whether this JSON array is considered equivalent to the provided
array, subject to the specified constraints.
|
boolean |
equals(JSONValue v,
boolean ignoreFieldNameCase,
boolean ignoreValueCase,
boolean ignoreArrayOrder)
Indicates whether this JSON value is considered equal to the provided JSON
value, subject to the specified constraints.
|
boolean |
equals(java.lang.Object o)
Indicates whether the provided object is equal to this JSON value.
|
java.util.List<JSONValue> |
getValues()
Retrieves the set of values contained in this JSON array.
|
int |
hashCode()
Retrieves a hash code for this JSON value.
|
boolean |
isEmpty()
Indicates whether this array is empty.
|
int |
size()
Retrieves the number of values contained in this array.
|
java.lang.String |
toNormalizedString()
Retrieves a normalized string representation of this array.
|
java.lang.String |
toNormalizedString(boolean ignoreFieldNameCase,
boolean ignoreValueCase,
boolean ignoreArrayOrder)
Retrieves a normalized string representation of this array.
|
void |
toNormalizedString(java.lang.StringBuilder buffer)
Appends a normalized string representation of this array to the provided
buffer.
|
void |
toNormalizedString(java.lang.StringBuilder buffer,
boolean ignoreFieldNameCase,
boolean ignoreValueCase,
boolean ignoreArrayOrder)
Appends a normalized string representation of this array to the provided
buffer.
|
JSONArray |
toNormalizedValue(boolean ignoreFieldNameCase,
boolean ignoreValueCase,
boolean ignoreArrayOrder)
Retrieves a normalized representation of this value using the provided
settings.
|
java.lang.String |
toSingleLineString()
Retrieves a single-line string representation of this array as it should
appear in a JSON object, including the surrounding square brackets.
|
void |
toSingleLineString(java.lang.StringBuilder buffer)
Appends a single-line string representation of this array as it should
appear in a JSON object, including the surrounding square brackets, to the
provided buffer.
|
java.lang.String |
toString()
Retrieves a string representation of this array as it should appear in a
JSON object, including the surrounding square brackets.
|
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of this value as it should appear in a
JSON object, including the surrounding square brackets,.
|
@NotNull public static final JSONArray EMPTY_ARRAY
public JSONArray(@Nullable JSONValue... values)
values
- The set of values to include in this JSON array. It may be
null
or empty to indicate that the array should be
empty.@NotNull public java.util.List<JSONValue> getValues()
public boolean isEmpty()
true
if this array does not contain any values, or
false
if this array contains at least one value.public int size()
public int hashCode()
public boolean equals(@Nullable java.lang.Object o)
public boolean equals(@NotNull JSONArray array, boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
array
- The array for which to make the determination.ignoreFieldNameCase
- Indicates whether to ignore differences in
capitalization in field names for any JSON
objects contained in the array.ignoreValueCase
- Indicates whether to ignore differences in
capitalization for array elements that are
JSON strings, as well as for the string values
of any JSON objects and arrays contained in
the array.ignoreArrayOrder
- Indicates whether to ignore differences in the
order of elements contained in the array.true
if this JSON array is considered equivalent to the
provided array (subject to the specified constraints), or
false
if not.public boolean equals(@NotNull JSONValue v, boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
equals
in class JSONValue
v
- The JSON value for which to make the
determination. It must not be null
.ignoreFieldNameCase
- Indicates whether to ignore differences in the
capitalization of JSON field names.ignoreValueCase
- Indicates whether to ignore differences in
the capitalization of JSON values that
represent strings.ignoreArrayOrder
- Indicates whether to ignore differences in the
order of elements in JSON arrays.true
if this JSON value is considered equal to the
provided JSON value (subject to the specified constraints), or
false
if not.public boolean contains(@NotNull JSONValue value, boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder, boolean recursive)
value
- The value for which to make the determination.ignoreFieldNameCase
- Indicates whether to ignore differences in
capitalization in field names for any JSON
objects contained in the array.ignoreValueCase
- Indicates whether to ignore differences in
capitalization for array elements that are
JSON strings, as well as for the string values
of any JSON objects and arrays contained in
the array.ignoreArrayOrder
- Indicates whether to ignore differences in the
order of elements contained in arrays. This
is only applicable if the provided value is
itself an array or is a JSON object that
contains values that are arrays.recursive
- Indicates whether to recursively look into any
arrays contained inside this array.true
if this JSON array contains an element with the
specified value, or false
if not.@NotNull public java.lang.String toString()
public void toString(@NotNull java.lang.StringBuilder buffer)
@NotNull public java.lang.String toSingleLineString()
toSingleLineString
in class JSONValue
public void toSingleLineString(@NotNull java.lang.StringBuilder buffer)
toSingleLineString
in class JSONValue
buffer
- The buffer to which the information should be appended.@NotNull public java.lang.String toNormalizedString()
toNormalizedString
in class JSONValue
public void toNormalizedString(@NotNull java.lang.StringBuilder buffer)
toNormalizedString
in class JSONValue
buffer
- The buffer to which the information should be appended.@NotNull public java.lang.String toNormalizedString(boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
toNormalizedString
in class JSONValue
ignoreFieldNameCase
- Indicates whether field names should be
treated in a case-sensitive (if false
)
or case-insensitive (if true
) manner.ignoreValueCase
- Indicates whether string field values should
be treated in a case-sensitive (if
false
) or case-insensitive (if
true
) manner.ignoreArrayOrder
- Indicates whether the order of elements in an
array should be considered significant (if
false
) or insignificant (if
true
).public void toNormalizedString(@NotNull java.lang.StringBuilder buffer, boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
toNormalizedString
in class JSONValue
buffer
- The buffer to which the information should be
appended.ignoreFieldNameCase
- Indicates whether field names should be
treated in a case-sensitive (if false
)
or case-insensitive (if true
) manner.ignoreValueCase
- Indicates whether string field values should
be treated in a case-sensitive (if
false
) or case-insensitive (if
true
) manner.ignoreArrayOrder
- Indicates whether the order of elements in an
array should be considered significant (if
false
) or insignificant (if
true
).@NotNull public JSONArray toNormalizedValue(boolean ignoreFieldNameCase, boolean ignoreValueCase, boolean ignoreArrayOrder)
toNormalizedValue
in class JSONValue
ignoreFieldNameCase
- Indicates whether field names should be
treated in a case-sensitive (if false
)
or case-insensitive (if true
) manner.ignoreValueCase
- Indicates whether string field values should
be treated in a case-sensitive (if
false
) or case-insensitive (if
true
) manner.ignoreArrayOrder
- Indicates whether the order of elements in an
array should be considered significant (if
false
) or insignificant (if
true
).public void appendToJSONBuffer(@NotNull JSONBuffer buffer)
appendToJSONBuffer
in class JSONValue
buffer
- The JSON buffer to which this value should be appended.public void appendToJSONBuffer(@NotNull java.lang.String fieldName, @NotNull JSONBuffer buffer)
appendToJSONBuffer
in class JSONValue
fieldName
- The name to use for the field.buffer
- The JSON buffer to which this value should be appended.