ikrs.json
Class JSONArray

java.lang.Object
  extended by ikrs.json.AbstractJSONValue
      extended by ikrs.json.JSONArray
All Implemented Interfaces:
JSONValue

public class JSONArray
extends AbstractJSONValue

This is the JSON array subclass.


Field Summary
 
Fields inherited from interface ikrs.json.JSONValue
FALSE, NULL, TRUE, TYPE_ARRAY, TYPE_BOOLEAN, TYPE_NULL, TYPE_NUMBER, TYPE_OBJECT, TYPE_STRING
 
Constructor Summary
JSONArray()
          Creates a new empty JSON array backed by an internal ArrayList instance.
JSONArray(java.util.List<JSONValue> array)
          Create a new JSON array.
 
Method Summary
 JSONArray asJSONArray()
          This method tries to convert this JSONValue into a JSONArray.
 JSONObject asJSONObject()
          This method tries to convert this JSONValue into a JSONObject.
 java.util.List<JSONValue> getArray()
          Get the array value as a List from this JSON value.
protected  java.util.List<JSONValue> getList()
          This method is a copy of getArray(), but with two differences: it is protected (only for subclasses) and does not thrown any exceptions.
 java.lang.String toString()
           
 void write(java.io.Writer writer)
          This method MUST write a valid JSON value to the passed writer.
 
Methods inherited from class ikrs.json.AbstractJSONValue
asJSONBoolean, asJSONNumber, asJSONString, getBoolean, getNumber, getObject, getString, getTypeName, isArray, isBoolean, isNull, isNumber, isObject, isString, isValidTypeID, toJSONString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JSONArray

public JSONArray()
Creates a new empty JSON array backed by an internal ArrayList instance.


JSONArray

public JSONArray(java.util.List<JSONValue> array)
          throws java.lang.NullPointerException
Create a new JSON array.

Parameters:
array - The array value this JSON value should have.
Throws:
java.lang.NullPointerException
Method Detail

getArray

public java.util.List<JSONValue> getArray()
                                   throws JSONException
Get the array value as a List from this JSON value.

Specified by:
getArray in interface JSONValue
Overrides:
getArray in class AbstractJSONValue
Returns:
The array from this JSON value. The array is returned as a Mist.
Throws:
JSONException - If this value does not represent an array.

asJSONArray

public JSONArray asJSONArray()
                      throws JSONException
This method tries to convert this JSONValue into a JSONArray. If that is not possible (because the contained value does not represent an array in any way) the method will throw an JSONException.

Specified by:
asJSONArray in interface JSONValue
Overrides:
asJSONArray in class AbstractJSONValue
Returns:
This JSON value as a JSON array.
Throws:
JSONException - If this value is not convertible to an array.

asJSONObject

public JSONObject asJSONObject()
                        throws JSONException
This method tries to convert this JSONValue into a JSONObject. If that is not possible (because the contained value does not represent an object in any way) the method will throw an JSONException.

Specified by:
asJSONObject in interface JSONValue
Overrides:
asJSONObject in class AbstractJSONValue
Returns:
This JSON value as a JSON object.
Throws:
JSONException - If this value is not convertible to an object.

write

public void write(java.io.Writer writer)
           throws java.io.IOException
This method MUST write a valid JSON value to the passed writer.

Specified by:
write in interface JSONValue
Specified by:
write in class AbstractJSONValue
Parameters:
writer - The writer to write to.
Throws:
java.io.IOException - If any IO errors occur.

getList

protected java.util.List<JSONValue> getList()
This method is a copy of getArray(), but with two differences: it is protected (only for subclasses) and does not thrown any exceptions. Note that this method does not create a copy of the internal list, so changes to the list reflect this JSONArray!

Returns:
The internal list, which is never null.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object