com.rubecula.jep
Class PresentableNumberFactory

java.lang.Object
  extended bycom.rubecula.jep.PresentableNumberFactory
All Implemented Interfaces:
org.nfunk.jep.type.NumberFactory

public class PresentableNumberFactory
extends java.lang.Object
implements org.nfunk.jep.type.NumberFactory

This class implements JEP's NumberFactory interface to allow the creation of JQuantity BaseNumbers when parsing expressions using JEP.

Note that this class does reference any jquantity classes at compile-time. Instead the references are dynamic.

// TODO implement createNumber(String) and also in createNumber(double) we need to be a bit smarter and use String when it's equivalent.

Since:
V_0_1
Version:
$Revision: 1.6 $
Author:
Robin Hillyard

Field Summary
private  PresentableFactoryInterface _PresentableFactory
          An implementation of PresentableFactoryInterface, in particular: PresentableFactory.
 
Constructor Summary
PresentableNumberFactory()
          Constructor of a factory for creating jquantity objects for the purposes of the JEP expression parser.
 
Method Summary
 java.lang.Object createNumber(double number)
          Method to implement the NumberFactory interface of the org.nfunk.jep package.
protected  java.lang.Object createNumber(double number, double bound)
          Method to create a Number with a given value and error bound.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_PresentableFactory

private PresentableFactoryInterface _PresentableFactory
An implementation of PresentableFactoryInterface, in particular: PresentableFactory. Used by the createNumber(double, double) method.

Constructor Detail

PresentableNumberFactory

public PresentableNumberFactory()
Constructor of a factory for creating jquantity objects for the purposes of the JEP expression parser. Objects returned will be instances of Presentable.

Method Detail

createNumber

public java.lang.Object createNumber(double number)
Method to implement the NumberFactory interface of the org.nfunk.jep package. Note that currently JEP always calls this method when creating any constant. Thus it is impossible in general to distinguish between fuzzy doubles, exact doubles, or even integers. The logic in this method is an attempt to deal with that problem. Calls createNumber(double,double) with an error bound of 0.

Specified by:
createNumber in interface org.nfunk.jep.type.NumberFactory
Parameters:
number - a number to be converted to an object.
Returns:
the object created, using an implementation of _PresentableFactoryInterface, in particular the com.rubecula.jquantiy.PresentableFactory class.

createNumber

protected java.lang.Object createNumber(double number,
                                        double bound)
Method to create a Number with a given value and error bound. If the number appears to be an integer, a presentable integer will be created. Otherwise, a presentable non-integer will be created. If any of these fail, a Double will be created.

Parameters:
number - a number to be converted to an object.
bound - - the relative error bound of the number.
Returns:
the object created, using an implementation of _PresentableFactoryInterface, in particular the com.rubecula.jquantiy.PresentableFactory class.