net.sourceforge.javajson
Class JsonValue

java.lang.Object
  extended by net.sourceforge.javajson.JsonValue

public class JsonValue
extends Object


Constructor Summary
JsonValue()
           
JsonValue(boolean val)
           
JsonValue(double val)
           
JsonValue(float val)
           
JsonValue(int val)
           
JsonValue(JsonArray val)
           
JsonValue(JsonObject val)
           
JsonValue(long val)
           
JsonValue(Object val)
           
JsonValue(String val)
           
 
Method Summary
static String byteToHex(byte b)
           
static String charToEscaped(char c)
           
static String escape(String str)
          Escapes strings for toString
 boolean getBoolean()
           
 double getDouble()
           
 float getFloat()
           
 int getInt()
           
 JsonArray getJsonArray()
           
 JsonObject getJsonObject()
           
 long getLong()
           
 JsonNativeType getNativeType()
           
 String getString()
           
 Class getValueClass()
          Deprecated. User getNativeType instead
 boolean isBoolean()
          Checks if the value is a boolean
 boolean isDouble()
          Checks if the value can be safely converted to this type without losing data.
 boolean isFloat()
          Checks if the value can be safely converted to this type without losing.
 boolean isInt()
          Checks if the value can be safely converted to this type without losing data.
 boolean isJsonArray()
           
 boolean isJsonObject()
           
 boolean isLong()
          Checks if the value can be safely converted to this type without losing data
 boolean isNull()
           
 boolean isSimilar(JsonValue obj)
          Checks if the type of this value is similar to that of another value.
 boolean isString()
          Returns true if the value is a number, boolean or string
 void setBoolean(boolean b)
           
 void setDouble(double d)
           
 void setFloat(float f)
           
 void setInt(int i)
           
 void setJsonArray(JsonArray array)
           
 void setJsonObject(JsonObject object)
           
 void setLong(long l)
           
protected  void setNull()
          Just sets the value to null
 void setString(String s)
           
 String toString()
           
protected  String toString(int spacing, int margin)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonValue

public JsonValue()

JsonValue

public JsonValue(boolean val)

JsonValue

public JsonValue(double val)

JsonValue

public JsonValue(float val)

JsonValue

public JsonValue(int val)

JsonValue

public JsonValue(JsonArray val)

JsonValue

public JsonValue(JsonObject val)

JsonValue

public JsonValue(long val)

JsonValue

public JsonValue(String val)

JsonValue

public JsonValue(Object val)
Method Detail

byteToHex

public static String byteToHex(byte b)

charToEscaped

public static String charToEscaped(char c)

getBoolean

public boolean getBoolean()

getDouble

public double getDouble()

getFloat

public float getFloat()

getInt

public int getInt()

getJsonArray

public JsonArray getJsonArray()

getJsonObject

public JsonObject getJsonObject()

getLong

public long getLong()

getString

public String getString()

getValueClass

public Class getValueClass()
Deprecated. User getNativeType instead

Returns the class of the value being used. For example, if setFloat or setDouble were used, Double.class is returned. If setInt or setLong is used, Long.class is returned.


getNativeType

public JsonNativeType getNativeType()

isBoolean

public boolean isBoolean()
Checks if the value is a boolean

Returns:

isDouble

public boolean isDouble()
Checks if the value can be safely converted to this type without losing data. This is true of any type of number

Returns:

isFloat

public boolean isFloat()
Checks if the value can be safely converted to this type without losing. It returns the same as isDouble as long as the value is not out of range TODO: check out of range errors

Returns:

isInt

public boolean isInt()
Checks if the value can be safely converted to this type without losing data. It returns the same as isLong as long as the value is not out of range TODO: check out of range errors

Returns:

isJsonArray

public boolean isJsonArray()

isJsonObject

public boolean isJsonObject()

isLong

public boolean isLong()
Checks if the value can be safely converted to this type without losing data

Returns:

isNull

public boolean isNull()

isSimilar

public boolean isSimilar(JsonValue obj)
Checks if the type of this value is similar to that of another value.

Parameters:
obj -
Returns:

isString

public boolean isString()
Returns true if the value is a number, boolean or string


setBoolean

public void setBoolean(boolean b)

setDouble

public void setDouble(double d)

setFloat

public void setFloat(float f)

setInt

public void setInt(int i)

setJsonArray

public void setJsonArray(JsonArray array)

setJsonObject

public void setJsonObject(JsonObject object)

setLong

public void setLong(long l)

setNull

protected void setNull()
Just sets the value to null


setString

public void setString(String s)

escape

public static String escape(String str)
Escapes strings for toString

Parameters:
str -
Returns:

toString

public String toString()
Overrides:
toString in class Object

toString

protected String toString(int spacing,
                          int margin)