MathTypepublic class MathType extends ClassType implements NumberTypeThis class represents the types java.math.BigDecimal and java.math.BigInteger. |
Constructors Summary |
---|
public MathType(String name, Class clazz, int enumType, TypeTable typetab)
super(name, clazz, enumType, typetab);
|
Methods Summary |
---|
public java.lang.Number | getValue(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.
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 boolean | isOrderable()A numeric wrapper class type defines an ordering.
return true;
| public java.lang.Number | negate(java.lang.Number value)Returns -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;
|
|