/** * Casts the specified value to Float data type. * * @see DataType#FLOAT */ private static Float toFloat(Object value) { if (value instanceof Float) { return (Float) value; } else if (value instanceof Integer) { Number number = (Number) value; return Float.valueOf(number.floatValue()); } throw new TypeCheckException(DataType.FLOAT, value); }
private static Number cast(DataType dataType, Number number) { switch (dataType) { case INTEGER: if (number instanceof Integer) { return number; } return Integer.valueOf(number.intValue()); case FLOAT: if (number instanceof Float) { return number; } return Float.valueOf(number.floatValue()); case DOUBLE: if (number instanceof Double) { return number; } return Double.valueOf(number.doubleValue()); default: break; } throw new EvaluationException(); }