FileDocCategorySizeDatePackage
MathType.javaAPI DocGlassfish v2 API5692Fri May 04 22:35:08 BST 2007com.sun.jdo.spi.persistence.support.sqlstore.query.util.type

MathType

public class MathType extends ClassType implements NumberType
This class represents the types java.math.BigDecimal and java.math.BigInteger.
author
Michael Bouschen
version
0.1

Fields Summary
Constructors Summary
public MathType(String name, Class clazz, int enumType, TypeTable typetab)

        super(name, clazz, enumType, typetab);
    
Methods Summary
public java.lang.NumbergetValue(java.lang.Number value)
Converts the specified value into a value of this numeric type. E.g. an Integer is converted into a BigDecimal, if this represents the type BigDecimal.

param
value value to be converted
return
converted value

        Number ret = null;

        if (value == null)
            ret = null;
        else if ("java.math.BigDecimal".equals(getName()))
        {
            if (value instanceof BigDecimal)
                ret = value;
            else if (value instanceof BigInteger)
                ret = new BigDecimal((BigInteger)value);
            else if (value instanceof Double)
                ret = new BigDecimal(((Double)value).toString());
            else if (value instanceof Float)
                ret = new BigDecimal(((Float)value).toString());
            else if (value instanceof Number)
                ret = BigDecimal.valueOf(((Number)value).longValue());
        }
        else if ("java.math.BigInteger".equals(getName()))
        {
            if (value instanceof BigInteger)
                ret = value;
            else if (value instanceof Double)
                ret = (new BigDecimal(((Double)value).toString())).toBigInteger();
            else if (value instanceof Float)
                ret = (new BigDecimal(((Float)value).toString())).toBigInteger();
            else if (value instanceof Number)
                ret = BigInteger.valueOf(((Number)value).longValue());
        }
        
        return ret;
    
public booleanisOrderable()
A numeric wrapper class type defines an ordering.

        return true;
    
public java.lang.Numbernegate(java.lang.Number value)
Returns -value.

param
value value to be negated
return
-value

        Number ret = null;

        if (value == null)
            ret = null;
        else if ("java.math.BigDecimal".equals(getName()))
        {
            if (value instanceof BigDecimal)
                ret = ((BigDecimal)value).negate();
            else if (value instanceof BigInteger)
                ret = new BigDecimal(((BigInteger)value).negate());
            else if (value instanceof Double)
                ret = (new BigDecimal(((Double)value).toString())).negate();
            else if (value instanceof Float)
                ret = (new BigDecimal(((Float)value).toString())).negate();
            else if (value instanceof Number)
                ret = BigDecimal.valueOf(-((Number)value).longValue());
        }
        else if ("java.math.BigInteger".equals(getName()))
        {
            if (value instanceof BigInteger)
                ret = ((BigInteger)value).negate();
            else if (value instanceof Double)
                ret = (new BigDecimal(((Double)value).toString())).negate().toBigInteger();
            else if (value instanceof Float)
                ret = (new BigDecimal(((Float)value).toString())).negate().toBigInteger();
            else if (value instanceof Number)
                ret = BigInteger.valueOf(-((Number)value).longValue());
        }
        
        return ret;