org.hecl
Class NumberThing

java.lang.Object
  extended by org.hecl.NumberThing
All Implemented Interfaces:
RealThing
Direct Known Subclasses:
FractionalThing, IntegralThing

public abstract class NumberThing
extends java.lang.Object
implements RealThing

The NumberThing class is what all numeric Thing types are derived from.

Version:
1.0
Author:
David N. Welton

Constructor Summary
NumberThing()
           
 
Method Summary
static NumberThing asNumber(Thing t)
          asNumber attempts to transform Thing t into a number of some sort.
abstract  byte byteValue()
          byteValue returns the number as a byte.
static Thing create(NumberThing n)
          The create method creates a new Thing from NumberThing n.
abstract  RealThing deepcopy()
          The deepcopy method must copy a RealThing and any values it contains.
abstract  double doubleValue()
          doubleValue returns the value as a double.
abstract  float floatValue()
          floatValue returns the value as a float.
abstract  java.lang.String getStringRep()
          The getStringRep method returns the string representation of a RealThing.
abstract  int intValue()
          intValue returns the number as an int.
abstract  boolean isFractional()
           
static boolean isFractional(Thing t)
          isFractional returns true if Thing t is a fractional (floating point) number, false if it isn't.
abstract  boolean isIntegral()
           
static boolean isIntegral(Thing t)
          isIntegral returns true if Thing t is a whole number (an int or long), or false if it isn't.
static boolean isNumber(RealThing rt)
           
static boolean isNumber(Thing t)
          isNumber returns true if Thing t is represented as a number internally.
abstract  long longValue()
          longValue returns the value as a long.
abstract  short shortValue()
          shortValue returns the number as a short.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.hecl.RealThing
thingclass
 

Constructor Detail

NumberThing

public NumberThing()
Method Detail

deepcopy

public abstract RealThing deepcopy()
                            throws HeclException
Description copied from interface: RealThing
The deepcopy method must copy a RealThing and any values it contains.

Specified by:
deepcopy in interface RealThing
Returns:
a RealThing value
Throws:
HeclException

getStringRep

public abstract java.lang.String getStringRep()
Description copied from interface: RealThing
The getStringRep method returns the string representation of a RealThing.

Specified by:
getStringRep in interface RealThing
Returns:
a String representation of the value

isNumber

public static boolean isNumber(Thing t)
isNumber returns true if Thing t is represented as a number internally.

Parameters:
t - a Thing value
Returns:
a boolean value

isNumber

public static boolean isNumber(RealThing rt)

isIntegral

public static boolean isIntegral(Thing t)
isIntegral returns true if Thing t is a whole number (an int or long), or false if it isn't.

Parameters:
t - a Thing value
Returns:
a boolean value

isFractional

public static boolean isFractional(Thing t)
isFractional returns true if Thing t is a fractional (floating point) number, false if it isn't.

Parameters:
t - a Thing value
Returns:
a boolean value

isIntegral

public abstract boolean isIntegral()

isFractional

public abstract boolean isFractional()

byteValue

public abstract byte byteValue()
byteValue returns the number as a byte.

Returns:
a byte value

shortValue

public abstract short shortValue()
shortValue returns the number as a short.

Returns:
a short value

intValue

public abstract int intValue()
intValue returns the number as an int.

Returns:
an int value

longValue

public abstract long longValue()
longValue returns the value as a long.

Returns:
a long value

floatValue

public abstract float floatValue()
floatValue returns the value as a float. Not available in CLDC 1.0

Returns:
a float value

doubleValue

public abstract double doubleValue()
doubleValue returns the value as a double. Not available in CLDC 1.0

Returns:
a double value

asNumber

public static NumberThing asNumber(Thing t)
                            throws java.lang.NumberFormatException
asNumber attempts to transform Thing t into a number of some sort. It first tries to get an int from t, then a long, and finally a double.

Parameters:
t - a Thing value
Returns:
a NumberThing value
Throws:
java.lang.NumberFormatException - when argument does not adhere to number format syntax.

create

public static Thing create(NumberThing n)
The create method creates a new Thing from NumberThing n.

Parameters:
n - a NumberThing value
Returns:
a Thing value