|
Eclipse Remote Application Platform | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.rap.json.JsonValue org.eclipse.rap.json.JsonArray
public class JsonArray
Represents a JSON array. A JSON array is a sequence of elements, which are JSON values (see
JsonValue
).
Elements can be added using one of the different add(...)
methods. Accepted values
are either instances of JsonValue
, or strings, primitive numbers, or boolean values.
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 ) { ... }
A n 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.
Field Summary |
---|
Fields inherited from class org.eclipse.rap.json.JsonValue |
---|
FALSE, NULL, TRUE |
Constructor Summary | |
---|---|
JsonArray()
Creates a new empty JsonArray. |
|
JsonArray(JsonArray array)
Creates a new JsonArray with the contents of the specified JSON array. |
Method Summary | |
---|---|
JsonArray |
add(boolean value)
Adds the JSON representation of the specified boolean value to the array. |
JsonArray |
add(double value)
Adds the JSON representation of the specified double value to the array. |
JsonArray |
add(float value)
Adds the JSON representation of the specified float value to the array. |
JsonArray |
add(JsonValue value)
Adds the specified JsonValue to the array. |
JsonArray |
add(long value)
Adds the JSON representation of the specified long value to the array. |
JsonArray |
add(java.lang.String value)
Adds the JSON representation of the specified string to the array. |
JsonArray |
asArray()
Returns this JSON value as JsonArray , assuming that this value represents a JSON
array. |
boolean |
equals(java.lang.Object object)
Indicates whether some other object is "equal to" this one according to the contract specified in Object.equals(Object) . |
JsonValue |
get(int index)
Returns the value of the element at the specified position in this array. |
int |
hashCode()
|
boolean |
isArray()
Detects whether this value represents a JSON array. |
boolean |
isEmpty()
Returns true if this array contains no elements. |
java.util.Iterator<JsonValue> |
iterator()
Returns an iterator over the values of this array in document order. |
static JsonArray |
readFrom(java.io.Reader reader)
Reads a JSON array from the given reader. |
static JsonArray |
readFrom(java.lang.String string)
Reads a JSON array from the given string. |
int |
size()
Returns the number of elements in this array. |
static JsonArray |
unmodifiableArray(JsonArray array)
Returns an unmodifiable wrapper for the specified JsonArray. |
java.util.List<JsonValue> |
values()
Returns a list of the values in this array in document order. |
protected void |
write(org.eclipse.rap.json.JsonWriter writer)
|
Methods inherited from class org.eclipse.rap.json.JsonValue |
---|
asBoolean, asDouble, asFloat, asInt, asLong, asObject, asString, isBoolean, isFalse, isNull, isNumber, isObject, isString, isTrue, toString, valueOf, valueOf, valueOf, valueOf, valueOf, writeTo |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public JsonArray()
public JsonArray(JsonArray array)
array
- the JsonArray to get the initial contents from, must not be null
Method Detail |
---|
public static JsonArray readFrom(java.io.Reader reader) throws java.io.IOException
reader
- the reader to read the JSON array from
java.io.IOException
- if an I/O error occurs in the reader
ParseException
- if the input is not valid JSON
java.lang.UnsupportedOperationException
- if the input does not contain a JSON arraypublic static JsonArray readFrom(java.lang.String string)
string
- the string that contains the JSON array
ParseException
- if the input is not valid JSON
java.lang.UnsupportedOperationException
- if the input does not contain a JSON arraypublic static JsonArray unmodifiableArray(JsonArray array)
The returned JsonArray is backed by the given array and reflects subsequent changes. Attempts
to modify the returned JsonArray result in an UnsupportedOperationException
.
array
- the JsonArray for which an unmodifiable JsonArray is to be returned
public JsonArray add(long value)
long
value to the array.
value
- the value to add to the array
public JsonArray add(float value)
float
value to the array.
value
- the value to add to the array
public JsonArray add(double value)
double
value to the array.
value
- the value to add to the array
public JsonArray add(boolean value)
boolean
value to the array.
value
- the value to add to the array
public JsonArray add(java.lang.String value)
value
- the string to add to the array
public JsonArray add(JsonValue value)
value
- the JsonValue to add to the array
public int size()
public boolean isEmpty()
true
if this array contains no elements.
true
if this array contains no elementspublic JsonValue get(int index)
index
- the index of the array element to return
java.lang.IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= size()).public java.util.List<JsonValue> values()
public java.util.Iterator<JsonValue> iterator()
iterator
in interface java.lang.Iterable<JsonValue>
protected void write(org.eclipse.rap.json.JsonWriter writer) throws java.io.IOException
write
in class JsonValue
java.io.IOException
public boolean isArray()
JsonValue
JsonArray
.
isArray
in class JsonValue
true
if this value is an instance of JsonArraypublic JsonArray asArray()
JsonValue
JsonArray
, assuming that this value represents a JSON
array. If this is not the case, an exception is thrown.
asArray
in class JsonValue
public int hashCode()
hashCode
in class JsonValue
public boolean equals(java.lang.Object object)
JsonValue
Object.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.
equals
in class JsonValue
object
- the reference object with which to compare
|
Eclipse Remote Application Platform | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright (c) EclipseSource and others 2002, 2013. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0