de.hpi.fgis.dude.util.data.json
Class JsonBoolean

java.lang.Object
  extended by de.hpi.fgis.dude.util.data.json.JsonBoolean
All Implemented Interfaces:
AutoJsonable, JsonAtomic, JsonValue, Jsonable, Comparable<JsonValue>

public class JsonBoolean
extends Object
implements JsonAtomic

JsonBoolean represents a boolean value that can be converted into Json.

Author:
Matthias Pohl

Nested Class Summary
 
Nested classes/interfaces inherited from interface de.hpi.fgis.dude.util.data.json.JsonValue
JsonValue.JsonType
 
Field Summary
static JsonBoolean FALSE
          A Json-convertible false.
static JsonBoolean TRUE
          A Json-convertible true.
 
Method Summary
 int compareTo(JsonValue other)
          Compares the current instance with the passed JsonValue.
static JsonBoolean createJsonBoolean(boolean boolVal)
          Returns the Json representation of the passed boolean value.
static JsonBoolean createJsonBoolean(String jsonCode)
          Returns a Json-convertible boolean based on the passed String.
 boolean equals(Object obj)
           
 void fromJson(DuDeJsonParser<?> jsonParser)
          Initializes the current instance using the passed DuDeJsonParser.
 String getStringValue()
          Returns the actual value converted into a String.
 JsonValue.JsonType getType()
          Returns JsonType.Boolean.
 boolean getValue()
          Returns the actual value of this JsonBoolean.
 int hashCode()
           
 int size()
          Returns 1 since JsonBoolean is an atomic value.
 void toJson(DuDeJsonGenerator jsonGenerator)
          Generates the Json code using the passed DuDeJsonGenerator.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TRUE

public static final JsonBoolean TRUE
A Json-convertible true.


FALSE

public static final JsonBoolean FALSE
A Json-convertible false.

Method Detail

createJsonBoolean

public static JsonBoolean createJsonBoolean(String jsonCode)
Returns a Json-convertible boolean based on the passed String.

Parameters:
jsonCode - The String that shall be converted into a Json-convertible boolean.
Returns:
TRUE if and only if jsonCode is the String "true" (case-insensitive); otherwise FALSE.

createJsonBoolean

public static JsonBoolean createJsonBoolean(boolean boolVal)
Returns the Json representation of the passed boolean value.

Parameters:
boolVal - The boolean value whose Json representation shall be returned.
Returns:
Returns TRUE or FALSE depending on the passed boolean value.

getType

public JsonValue.JsonType getType()
Returns JsonType.Boolean.

Specified by:
getType in interface JsonValue
Returns:
The type of the current instance.
See Also:
JsonValue.getType()

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

size

public int size()
Returns 1 since JsonBoolean is an atomic value.

Specified by:
size in interface JsonValue
Returns:
The number of concrete Java objects that are collected by the current instance.
See Also:
JsonValue.size()

compareTo

public int compareTo(JsonValue other)
Description copied from interface: JsonValue
Compares the current instance with the passed JsonValue. Instances of different JsonValue.JsonTypes are ordered lexicographically except for JsonValue.JsonType.Null. The above mentioned requirements define the following order: null == JsonValue.JsonType.Null < JsonValue.JsonType.Array < JsonValue.JsonType.Boolean < JsonValue.JsonType.Number < JsonValue.JsonType.Record < JsonValue.JsonType.String.

Specified by:
compareTo in interface JsonValue
Specified by:
compareTo in interface Comparable<JsonValue>
See Also:
Comparable.compareTo(Object)

getValue

public boolean getValue()
Returns the actual value of this JsonBoolean.

Returns:
The actual value of this JsonBoolean.

toJson

public void toJson(DuDeJsonGenerator jsonGenerator)
            throws org.codehaus.jackson.JsonGenerationException,
                   IOException
Description copied from interface: Jsonable
Generates the Json code using the passed DuDeJsonGenerator.

Specified by:
toJson in interface Jsonable
Parameters:
jsonGenerator - The DuDeJsonGenerator that is used internally.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while writing to the output.

fromJson

public void fromJson(DuDeJsonParser<?> jsonParser)
              throws org.codehaus.jackson.JsonParseException,
                     IOException
Description copied from interface: Jsonable
Initializes the current instance using the passed DuDeJsonParser.

Specified by:
fromJson in interface Jsonable
Parameters:
jsonParser - The parser that is used for extracting the data out of the Json.
Throws:
org.codehaus.jackson.JsonParseException - If an error occurs while parsing the Json.
IOException - If an error occurs while reading from the stream.

getStringValue

public String getStringValue()
Description copied from interface: JsonAtomic
Returns the actual value converted into a String. This method should be preferred in contrast to #toString().

Specified by:
getStringValue in interface JsonAtomic
Returns:
The actual value converted into a String.


Copyright © 2011 Hasso Plattner Institute - Chair of Information Systems. All Rights Reserved.