org.elkoserver.json
Class JSONArray

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<Object>
              extended by org.elkoserver.json.JSONArray
All Implemented Interfaces:
Serializable, Cloneable, Iterable<Object>, Collection<Object>, List<Object>, RandomAccess

public class JSONArray
extends ArrayList<Object>

A parsed JSON array. This class represents a JSON array that has been received or is being constructed.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
JSONArray()
          Construct a new, empty array.
 
Method Summary
 JSONArray getArray(int index)
          Obtain an array-valued element value.
 boolean getBoolean(int index)
          Obtain the boolean value of an element.
 double getDouble(int index)
          Obtain the double value of an element.
 int getInt(int index)
          Obtain the integer value of an element.
 long getLong(int index)
          Obtain the long value of an element.
 JSONObject getObject(int index)
          Obtain the JSON object value of an element.
 String getString(int index)
          Obtain the string value of an element.
 JSONLiteralArray literal(EncodeControl control)
          Convert this JSONArray into a JSONLiteralArray.
 String sendableString()
          Obtain a string representation of this array suitable for output to a connection.
 String toString()
          Obtain a printable string representation of this JSON array.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

JSONArray

public JSONArray()
Construct a new, empty array.

Method Detail

literal

public JSONLiteralArray literal(EncodeControl control)
Convert this JSONArray into a JSONLiteralArray.

Parameters:
control - Encode control determining what flavor of encoding is being done.

getArray

public JSONArray getArray(int index)
                   throws JSONDecodingException
Obtain an array-valued element value.

Parameters:
index - The index of the array value sought.
Returns:
The JSON array value of element number 'index'.
Throws:
JSONDecodingException - if the value is not an array.

getBoolean

public boolean getBoolean(int index)
                   throws JSONDecodingException
Obtain the boolean value of an element.

Parameters:
index - The index of the boolean value sought.
Returns:
The boolean value of element number 'index'.
Throws:
JSONDecodingException - if the value is not a boolean.

getDouble

public double getDouble(int index)
                 throws JSONDecodingException
Obtain the double value of an element.

Parameters:
index - The index of the double value sought.
Returns:
The double value of element number 'index'.
Throws:
JSONDecodingException - if the value is not a number.

getInt

public int getInt(int index)
           throws JSONDecodingException
Obtain the integer value of an element.

Parameters:
index - The index of the integer value sought.
Returns:
The int value of element number 'index'.
Throws:
JSONDecodingException - if the value is not a number.

getLong

public long getLong(int index)
             throws JSONDecodingException
Obtain the long value of an element.

Parameters:
index - The index of the long value sought.
Returns:
The long value of element number 'index'.
Throws:
JSONDecodingException - if the value is not a number.

getObject

public JSONObject getObject(int index)
                     throws JSONDecodingException
Obtain the JSON object value of an element.

Parameters:
index - The index of the object value sought.
Returns:
The JSON object value of element number 'index'.
Throws:
JSONDecodingException - if the value is not a JSON object.

getString

public String getString(int index)
                 throws JSONDecodingException
Obtain the string value of an element.

Parameters:
index - The index of the string value sought.
Returns:
The string value of element number 'index'.
Throws:
JSONDecodingException - if the value is not a string.

sendableString

public String sendableString()
Obtain a string representation of this array suitable for output to a connection.

Returns:
a sendable string representation of this array.

toString

public String toString()
Obtain a printable string representation of this JSON array.

Overrides:
toString in class AbstractCollection<Object>
Returns:
a printable representation of this array.