Class JsonArray
- All Implemented Interfaces:
- Serializable,- Iterable<JsonValue>
 Elements can be added using the add(...) methods which accept instances of
 JsonValue, strings, primitive numbers, and boolean values. To replace an element of an
 array, use the set(int, ...) methods.
 
 Elements can be accessed by their index using get(int). This class also supports
 iterating over the elements in document order using an iterator() or an enhanced for
 loop:
 
 for( JsonValue value : jsonArray ) {
   ...
 }
 
 
 An equivalent List can be obtained from the method values().
 
 Note that this class is not thread-safe. If multiple threads access a
 JsonArray instance concurrently, while at least one of these threads modifies the
 contents of this array, access to the instance must be synchronized externally. Failure to do so
 may lead to an inconsistent state.
 
This class is not supposed to be extended by clients.
- Since:
- 2.1
- See Also:
- 
Field Summary
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionadd(boolean value) Adds the JSON representation of the specifiedbooleanvalue to the array.add(double value) Adds the JSON representation of the specifieddoublevalue to the array.add(float value) Adds the JSON representation of the specifiedfloatvalue to the array.add(int value) Adds the JSON representation of the specifiedintvalue to the array.add(long value) Adds the JSON representation of the specifiedlongvalue to the array.Adds the JSON representation of the specified string to the array.Adds the specified JSON value to the array.asArray()Returns this JSON value asJsonArray, assuming that this value represents a JSON array.booleanIndicates whether some other object is "equal to" this one according to the contract specified inObject.equals(Object).get(int index) Returns the value of the element at the specified position in this array.inthashCode()booleanisArray()Detects whether this value represents a JSON array.booleanisEmpty()Returnstrueif this array contains no elements.iterator()Returns an iterator over the values of this array in document order.static JsonArrayReads a JSON array from the given reader.static JsonArrayReads a JSON array from the given string.set(int index, boolean value) Replaces the element at the specified position in this array with the JSON representation of the specifiedbooleanvalue.set(int index, double value) Replaces the element at the specified position in this array with the JSON representation of the specifieddoublevalue.set(int index, float value) Replaces the element at the specified position in this array with the JSON representation of the specifiedfloatvalue.set(int index, int value) Replaces the element at the specified position in this array with the JSON representation of the specifiedintvalue.set(int index, long value) Replaces the element at the specified position in this array with the JSON representation of the specifiedlongvalue.Replaces the element at the specified position in this array with the JSON representation of the specified string.Replaces the element at the specified position in this array with the specified JSON value.intsize()Returns the number of elements in this array.static JsonArrayunmodifiableArray(JsonArray array) Returns an unmodifiable wrapper for the specified JsonArray.values()Returns a list of the values in this array in document order.protected voidwrite(org.eclipse.rap.json.JsonWriter writer) Methods inherited from class org.eclipse.rap.json.JsonValueasBoolean, asDouble, asFloat, asInt, asLong, asObject, asString, isBoolean, isFalse, isNull, isNumber, isObject, isString, isTrue, toString, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, writeToMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.IterableforEach, spliterator
- 
Constructor Details- 
JsonArraypublic JsonArray()Creates a new empty JsonArray.
- 
JsonArrayCreates a new JsonArray with the contents of the specified JSON array.- Parameters:
- array- the JsonArray to get the initial contents from, must not be- null
 
 
- 
- 
Method Details- 
readFromReads a JSON array from the given reader.Characters are read in chunks and buffered internally, therefore wrapping an existing reader in an additional BufferedReaderdoes not improve reading performance.- Parameters:
- reader- the reader to read the JSON array from
- Returns:
- the JSON array that has been read
- Throws:
- IOException- if an I/O error occurs in the reader
- ParseException- if the input is not valid JSON
- UnsupportedOperationException- if the input does not contain a JSON array
 
- 
readFromReads a JSON array from the given string.- Parameters:
- string- the string that contains the JSON array
- Returns:
- the JSON array that has been read
- Throws:
- ParseException- if the input is not valid JSON
- UnsupportedOperationException- if the input does not contain a JSON array
 
- 
unmodifiableArrayReturns an unmodifiable wrapper for the specified JsonArray. This method allows to provide read-only access to a JsonArray.The returned JsonArray is backed by the given array and reflects subsequent changes. Attempts to modify the returned JsonArray result in an UnsupportedOperationException.- Parameters:
- array- the JsonArray for which an unmodifiable JsonArray is to be returned
- Returns:
- an unmodifiable view of the specified JsonArray
 
- 
addAdds the JSON representation of the specifiedintvalue to the array.- Parameters:
- value- the value to add to the array
- Returns:
- the array itself, to enable method chaining
- Since:
- 2.2
 
- 
addAdds the JSON representation of the specifiedlongvalue to the array.- Parameters:
- value- the value to add to the array
- Returns:
- the array itself, to enable method chaining
 
- 
addAdds the JSON representation of the specifiedfloatvalue to the array.- Parameters:
- value- the value to add to the array
- Returns:
- the array itself, to enable method chaining
 
- 
addAdds the JSON representation of the specifieddoublevalue to the array.- Parameters:
- value- the value to add to the array
- Returns:
- the array itself, to enable method chaining
 
- 
addAdds the JSON representation of the specifiedbooleanvalue to the array.- Parameters:
- value- the value to add to the array
- Returns:
- the array itself, to enable method chaining
 
- 
addAdds the JSON representation of the specified string to the array.- Parameters:
- value- the string to add to the array
- Returns:
- the array itself, to enable method chaining
 
- 
addAdds the specified JSON value to the array.- Parameters:
- value- the JsonValue to add to the array, must not be- null
- Returns:
- the array itself, to enable method chaining
 
- 
setReplaces the element at the specified position in this array with the JSON representation of the specifiedintvalue.- Parameters:
- index- the index of the array element to replace
- value- the value to be stored at the specified array position
- Returns:
- the array itself, to enable method chaining
- Throws:
- IndexOutOfBoundsException- if the index is out of range, i.e.- index < 0or- index >= size
- Since:
- 2.2
 
- 
setReplaces the element at the specified position in this array with the JSON representation of the specifiedlongvalue.- Parameters:
- index- the index of the array element to replace
- value- the value to be stored at the specified array position
- Returns:
- the array itself, to enable method chaining
- Throws:
- IndexOutOfBoundsException- if the index is out of range, i.e.- index < 0or- index >= size
- Since:
- 2.2
 
- 
setReplaces the element at the specified position in this array with the JSON representation of the specifiedfloatvalue.- Parameters:
- index- the index of the array element to replace
- value- the value to be stored at the specified array position
- Returns:
- the array itself, to enable method chaining
- Throws:
- IndexOutOfBoundsException- if the index is out of range, i.e.- index < 0or- index >= size
- Since:
- 2.2
 
- 
setReplaces the element at the specified position in this array with the JSON representation of the specifieddoublevalue.- Parameters:
- index- the index of the array element to replace
- value- the value to be stored at the specified array position
- Returns:
- the array itself, to enable method chaining
- Throws:
- IndexOutOfBoundsException- if the index is out of range, i.e.- index < 0or- index >= size
- Since:
- 2.2
 
- 
setReplaces the element at the specified position in this array with the JSON representation of the specifiedbooleanvalue.- Parameters:
- index- the index of the array element to replace
- value- the value to be stored at the specified array position
- Returns:
- the array itself, to enable method chaining
- Throws:
- IndexOutOfBoundsException- if the index is out of range, i.e.- index < 0or- index >= size
- Since:
- 2.2
 
- 
setReplaces the element at the specified position in this array with the JSON representation of the specified string.- Parameters:
- index- the index of the array element to replace
- value- the string to be stored at the specified array position
- Returns:
- the array itself, to enable method chaining
- Throws:
- IndexOutOfBoundsException- if the index is out of range, i.e.- index < 0or- index >= size
- Since:
- 2.2
 
- 
setReplaces the element at the specified position in this array with the specified JSON value.- Parameters:
- index- the index of the array element to replace
- value- the value to be stored at the specified array position, must not be- null
- Returns:
- the array itself, to enable method chaining
- Throws:
- IndexOutOfBoundsException- if the index is out of range, i.e.- index < 0or- index >= size
- Since:
- 2.2
 
- 
sizepublic int size()Returns the number of elements in this array.- Returns:
- the number of elements in this array
 
- 
isEmptypublic boolean isEmpty()Returnstrueif this array contains no elements.- Returns:
- trueif this array contains no elements
 
- 
getReturns the value of the element at the specified position in this array.- Parameters:
- index- the index of the array element to return
- Returns:
- the value of the element at the specified position
- Throws:
- IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size()).
 
- 
valuesReturns a list of the values in this array in document order. The returned list is backed by this array and will reflect subsequent changes. It cannot be used to modify this array. Attempts to modify the returned list will result in an exception.- Returns:
- a list of the values in this array
 
- 
iteratorReturns an iterator over the values of this array in document order. The returned iterator cannot be used to modify this array.
- 
write- Specified by:
- writein class- JsonValue
- Throws:
- IOException
 
- 
isArraypublic boolean isArray()Description copied from class:JsonValueDetects whether this value represents a JSON array. If this is the case, this value is an instance ofJsonArray.
- 
asArrayDescription copied from class:JsonValueReturns this JSON value asJsonArray, assuming that this value represents a JSON array. If this is not the case, an exception is thrown.
- 
hashCodepublic int hashCode()
- 
equalsDescription copied from class:JsonValueIndicates whether some other object is "equal to" this one according to the contract specified inObject.equals(Object).Two JsonValues are considered equal if and only if they represent the same JSON text. As a consequence, two given JsonObjects may be different even though they contain the same set of names with the same values, but in a different order. 
 
-