}
private static InternalNumber getInternalNumberFromType(Object in, int type) {
if (in == null)
return new InternalNumber(0, MATH_CONTEXT);
switch (type) {
case BIG_DECIMAL:
return new InternalNumber(((BigDecimal) in).doubleValue());
case DataTypes.BIG_INTEGER:
return new InternalNumber((BigInteger) in, MathContext.DECIMAL128);
case DataTypes.INTEGER:
case DataTypes.W_INTEGER:
return new InternalNumber((Integer) in, MathContext.DECIMAL32);
case DataTypes.LONG:
case DataTypes.W_LONG:
return new InternalNumber((Long) in, MathContext.DECIMAL64);
case DataTypes.STRING:
return new InternalNumber((String) in, MathContext.DECIMAL64);
case DataTypes.FLOAT:
case DataTypes.W_FLOAT:
return new InternalNumber((Float) in, MathContext.DECIMAL64);
case DataTypes.DOUBLE:
case DataTypes.W_DOUBLE:
return new InternalNumber((Double) in, MathContext.DECIMAL64);
case DataTypes.SHORT:
case DataTypes.W_SHORT:
return new InternalNumber((Short) in, MathContext.DECIMAL32);
case DataTypes.CHAR:
case DataTypes.W_CHAR:
return new InternalNumber((Character) in, MathContext.DECIMAL32);
case DataTypes.BOOLEAN:
case DataTypes.W_BOOLEAN:
return new InternalNumber(((Boolean) in) ? 1 : 0);
case DataTypes.UNIT:
return new InternalNumber(((Unit) in).getValue(), MathContext.DECIMAL64);
case DataTypes.W_BYTE:
case DataTypes.BYTE:
return new InternalNumber(((Byte) in).intValue());
}
throw new RuntimeException("cannot convert <" + in + "> to a numeric type: " + in.getClass() + " [" + type + "]");