xv.json
Class JSONNumber

java.lang.Object
  extended by xv.json.JSONVariant
      extended by xv.json.JSONNumber

public class JSONNumber
extends JSONVariant

A JSON number. Wraps a Java Number object.

If Java supported multiple inheritance, this would also extend Number. An interface for numeric-like objects would be nice too.

Author:
xv

Constructor Summary
JSONNumber(Number number)
          Wraps the given Java Number.
 
Method Summary
 byte byteValue()
          Returns the value as a byte.
 double doubleValue()
          Returns the value as a double.
 boolean equals(Object object)
           
 float floatValue()
          Returns the value as a float.
 Number getNumber()
          Gets the wrapped Java Number.
 String getType()
          Returns "number".
 int hashCode()
           
 int intValue()
          Returns the value as an int.
 long longValue()
          Returns the value as a long.
 short shortValue()
          Returns the value as a short.
 String toString()
          Returns the string value of the number.
static JSONNumber valueOf(String s)
          Parses the given string as if it were a JSON number, returning an appropriately wrapped Number.
 
Methods inherited from class xv.json.JSONVariant
toJSON, write
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JSONNumber

public JSONNumber(Number number)
Wraps the given Java Number.

Parameters:
number - the number to wrap
Method Detail

getNumber

public Number getNumber()
Gets the wrapped Java Number.

Returns:
the wrapped number

byteValue

public byte byteValue()
Returns the value as a byte.

Returns:
the value as a byte
See Also:
Number.byteValue()

shortValue

public short shortValue()
Returns the value as a short.

Returns:
the value as a short
See Also:
Number.shortValue()

intValue

public int intValue()
Returns the value as an int.

Returns:
the value as an int
See Also:
Number.intValue(), BigInteger.intValue()

longValue

public long longValue()
Returns the value as a long.

Returns:
the value as a long
See Also:
Number.longValue(), BigInteger.longValue()

floatValue

public float floatValue()
Returns the value as a float.

Returns:
the value as a float
See Also:
Number.floatValue(), BigInteger.floatValue()

doubleValue

public double doubleValue()
Returns the value as a double.

Returns:
the value as a double
See Also:
Number.doubleValue(), BigInteger.doubleValue()

toString

public String toString()
Returns the string value of the number. This (should) be a value that can be parsed back into an equivalent JSONNumber via valueOf(String).

Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

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

getType

public String getType()
Returns "number".

Specified by:
getType in class JSONVariant
Returns:

valueOf

public static JSONNumber valueOf(String s)
Parses the given string as if it were a JSON number, returning an appropriately wrapped Number.

Parameters:
s - the string to parse
Returns:
a parsed number
Throws:
NullPointerException - if the given string is null
NumberFormatException - if the number cannot be parsed


Copyright © 2008-2011. All Rights Reserved.