ikrs.json
Class JSONBoolean

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

public class JSONBoolean
extends AbstractJSONValue

This is the JSON boolean 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
JSONBoolean(java.lang.Boolean bool)
          Create a new JSON boolean.
 
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.
 JSONString asJSONString()
          This method tries to convert this JSONValue into a JSONString.
 java.lang.Boolean getBoolean()
          Get the boolean from this JSON value.
static java.lang.Boolean parseBoolean(java.lang.String str, boolean caseSensitive)
          This static method is the equivalent to Java's Boolean.parseBoolean(String).
static JSONBoolean parseJSONBoolean(java.lang.String str, boolean caseSensitive)
          This static method is the equivalent to Java's Boolean.parseBoolean(String).
 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
asJSONNumber, asJSONObject, getArray, 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

JSONBoolean

public JSONBoolean(java.lang.Boolean bool)
            throws java.lang.NullPointerException
Create a new JSON boolean.

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

getBoolean

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

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

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
Overrides:
asJSONBoolean in class AbstractJSONValue
Returns:
This JSON value as a JSON boolean.
Throws:
JSONException - If this value is not convertible to a boolean.

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
Overrides:
asJSONString in class AbstractJSONValue
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
Overrides:
asJSONArray in class AbstractJSONValue
Returns:
This JSON value as a JSON array.
Throws:
JSONException - If this value is not convertible to an array.

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.

toString

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

parseBoolean

public static java.lang.Boolean parseBoolean(java.lang.String str,
                                             boolean caseSensitive)
                                      throws java.lang.NullPointerException,
                                             java.lang.NumberFormatException
This static method is the equivalent to Java's Boolean.parseBoolean(String). It expects a String containing a number and converts it into a Java Number object. If the passed string does not represent a boolean the method throws a NumberFormatException.

Parameters:
str - The string to be parsed.
Returns:
The parsed boolean value.
Throws:
java.lang.NullPointerException - If the passed string is null.
JSONException - If the passed string does not represent a boolean.
java.lang.NumberFormatException

parseJSONBoolean

public static JSONBoolean parseJSONBoolean(java.lang.String str,
                                           boolean caseSensitive)
                                    throws java.lang.NullPointerException,
                                           JSONException
This static method is the equivalent to Java's Boolean.parseBoolean(String). It expects a String containing a number and converts it into a JSONBoolean object. If the passed string does not represent a boolean the method throws a JSONException.

Parameters:
str - The string to be parsed.
Returns:
The parsed JSON number value.
Throws:
java.lang.NullPointerException - If the passed string is null.
JSONException - If the passed string does not represent a number.