ikrs.json
Class AbstractJSONValue

java.lang.Object
  extended by ikrs.json.AbstractJSONValue
All Implemented Interfaces:
JSONValue
Direct Known Subclasses:
JSONArray, JSONBoolean, JSONNull, JSONNumber, JSONObject, JSONString

public abstract class AbstractJSONValue
extends java.lang.Object
implements JSONValue


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
protected AbstractJSONValue(int type)
           
 
Method Summary
 JSONArray asJSONArray()
          This method tries to convert this JSONValue into a JSONArray.
 JSONBoolean asJSONBoolean()
          This method tries to convert this JSONValue into a JSONBoolean.
 JSONNumber asJSONNumber()
          This method tries to convert this JSONValue into a JSONNumber.
 JSONObject asJSONObject()
          This method tries to convert this JSONValue into a JSONObject.
 JSONString asJSONString()
          This method tries to convert this JSONValue into a JSONString.
 java.util.List<JSONValue> getArray()
          Get the array value as a List from this JSON value.
 java.lang.Boolean getBoolean()
          Get the boolean from this JSON value.
 java.lang.Number getNumber()
          Get the number from this JSON value.
 java.util.Map<java.lang.String,JSONValue> getObject()
          Get the object value as a Map from this JSON value.
 java.lang.String getString()
          Get the string from this JSON value.
 java.lang.String getTypeName()
           
 boolean isArray()
          This method indicates if this JSON value is an array.
 boolean isBoolean()
          This method indicates if this JSON value is a boolean.
 boolean isNull()
          This method indicates if this is JSON NULL.
 boolean isNumber()
          This method indicates if this JSON value is a number.
 boolean isObject()
          This method indicates if this JSON value is an object.
 boolean isString()
          This method indicates if this JSON value is a string.
 boolean isValidTypeID(int type)
          This method indicates if the passed type ID is supported by this class.
 java.lang.String toJSONString()
          Converts this JSON value into a valid JSON string.
abstract  void write(java.io.Writer writer)
          This method MUST write a valid JSON value to the passed writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractJSONValue

protected AbstractJSONValue(int type)
                     throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException
Method Detail

isNumber

public boolean isNumber()
This method indicates if this JSON value is a number.

Specified by:
isNumber in interface JSONValue
Returns:
true if this value represents a number.

isBoolean

public boolean isBoolean()
This method indicates if this JSON value is a boolean.

Specified by:
isBoolean in interface JSONValue
Returns:
true if this value represents a boolean value.

isString

public boolean isString()
This method indicates if this JSON value is a string.

Specified by:
isString in interface JSONValue
Returns:
true if this value represents a string.

isArray

public boolean isArray()
This method indicates if this JSON value is an array.

Specified by:
isArray in interface JSONValue
Returns:
true if this value represents an array.

isObject

public boolean isObject()
This method indicates if this JSON value is an object.

Specified by:
isObject in interface JSONValue
Returns:
true if this value represents an array.

isNull

public boolean isNull()
This method indicates if this is JSON NULL.

Specified by:
isNull in interface JSONValue
Returns:
true if this JSON value is NULL (null).

getNumber

public java.lang.Number getNumber()
                           throws JSONException
Get the number from this JSON value.

Specified by:
getNumber in interface JSONValue
Returns:
The number from this JSON value.
Throws:
JSONException - If this value does not represent a number.

getBoolean

public java.lang.Boolean getBoolean()
                             throws JSONException
Get the boolean from this JSON value.

Specified by:
getBoolean in interface JSONValue
Returns:
The boolean value from this JSON value.
Throws:
JSONException - If this value does not represent a boolean value.

getString

public java.lang.String getString()
                           throws JSONException
Get the string from this JSON value.

Specified by:
getString in interface JSONValue
Returns:
The string value from this JSON value.
Throws:
JSONException - If this value does not represent a string.

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
Returns:
The array from this JSON value. The array is returned as a Mist.
Throws:
JSONException - If this value does not represent an array.

getObject

public java.util.Map<java.lang.String,JSONValue> getObject()
                                                    throws JSONException
Get the object value as a Map from this JSON value.

Specified by:
getObject in interface JSONValue
Returns:
The object from this JSON value. The object is returned as a Map.
Throws:
JSONException - If this value does not represent an object.

asJSONBoolean

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

Specified by:
asJSONBoolean in interface JSONValue
Returns:
This JSON value as a JSON boolean.
Throws:
JSONException - If this value is not convertible to a boolean.

asJSONNumber

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

Specified by:
asJSONNumber in interface JSONValue
Returns:
This JSON value as a JSON number.
Throws:
JSONException - If this value is not convertible to a number.

asJSONString

public JSONString asJSONString()
                        throws JSONException
This method tries to convert this JSONValue into a JSONString. If that is not possible (because the contained value does not represent a string in any way) the method will throw an JSONException. Note: due to the fact that JSON is usually represented by a string EACH JSON VALUE SHOULD BE CONVERTIBLE TO A STRING.

Specified by:
asJSONString in interface JSONValue
Returns:
This JSON value as a JSON string.
Throws:
JSONException - If this value is not convertible to a boolean.

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
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
Returns:
This JSON value as a JSON object.
Throws:
JSONException - If this value is not convertible to an object.

write

public abstract 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
Parameters:
writer - The writer to write to.
Throws:
java.io.IOException - If any IO errors occur.

toJSONString

public java.lang.String toJSONString()
Converts this JSON value into a valid JSON string.

Specified by:
toJSONString in interface JSONValue
Returns:
This value as a JSON string.

isValidTypeID

public boolean isValidTypeID(int type)
This method indicates if the passed type ID is supported by this class.

Parameters:
type - The type ID.
Returns:
true If the passed type ID is supported by this class

getTypeName

public java.lang.String getTypeName()