@Test public void getCommonDataType(){ assertEquals(DataType.DOUBLE, TypeUtil.getCommonDataType(DataType.DOUBLE, DataType.DOUBLE)); assertEquals(DataType.DOUBLE, TypeUtil.getCommonDataType(DataType.DOUBLE, DataType.FLOAT)); assertEquals(DataType.DOUBLE, TypeUtil.getCommonDataType(DataType.DOUBLE, DataType.INTEGER)); try { TypeUtil.getCommonDataType(DataType.DOUBLE, DataType.BOOLEAN); fail(); } catch(EvaluationException ee){ } assertEquals(DataType.DOUBLE, TypeUtil.getCommonDataType(DataType.FLOAT, DataType.DOUBLE)); assertEquals(DataType.FLOAT, TypeUtil.getCommonDataType(DataType.FLOAT, DataType.FLOAT)); assertEquals(DataType.FLOAT, TypeUtil.getCommonDataType(DataType.FLOAT, DataType.INTEGER)); assertEquals(DataType.DOUBLE, TypeUtil.getCommonDataType(DataType.INTEGER, DataType.DOUBLE)); assertEquals(DataType.FLOAT, TypeUtil.getCommonDataType(DataType.INTEGER, DataType.FLOAT)); assertEquals(DataType.INTEGER, TypeUtil.getCommonDataType(DataType.INTEGER, DataType.INTEGER)); }
static public DataType getCommonDataType(DataType left, DataType right){ if((left).equals(right)){ switch(left){ case DOUBLE: case FLOAT: case INTEGER: return left; default: break; } } else if((DataType.DOUBLE).equals(left)){ if((DataType.FLOAT).equals(right) || (DataType.INTEGER).equals(right)){ return left; } } else if((DataType.FLOAT).equals(left)){ if((DataType.DOUBLE).equals(right)){ return right; } else if((DataType.INTEGER).equals(right)){ return left; } } else if((DataType.INTEGER).equals(left)){ if((DataType.DOUBLE).equals(right) || (DataType.FLOAT).equals(right)){ return right; } } throw new EvaluationException("No PMML data type for the intersection of PMML data types " + left.value() + " and " + right.value()); }
TypeUtil { static public DataType getCommonDataType(DataType left, DataType right){ if((left).equals(right)){ switch(left){ case DOUBLE: case FLOAT: case INTEGER: return left; default: break; } } else if((DataType.DOUBLE).equals(left)){ if((DataType.FLOAT).equals(right) || (DataType.INTEGER).equals(right)){ return left; } } else if((DataType.FLOAT).equals(left)){ if((DataType.DOUBLE).equals(right)){ return right; } else if((DataType.INTEGER).equals(right)){ return left; } } else if((DataType.INTEGER).equals(left)){ if((DataType.DOUBLE).equals(right) || (DataType.FLOAT).equals(right)){ return right; } } throw new EvaluationException("No PMML data type for the intersection of PMML data types " + left.value() + " and " + right.value()); } }
TypeUtil { static public DataType getCommonDataType(DataType left, DataType right){ if((left).equals(right)){ switch(left){ case DOUBLE: case FLOAT: case INTEGER: return left; default: break; } } else if((DataType.DOUBLE).equals(left)){ if((DataType.FLOAT).equals(right) || (DataType.INTEGER).equals(right)){ return left; } } else if((DataType.FLOAT).equals(left)){ if((DataType.DOUBLE).equals(right)){ return right; } else if((DataType.INTEGER).equals(right)){ return left; } } else if((DataType.INTEGER).equals(left)){ if((DataType.DOUBLE).equals(right) || (DataType.FLOAT).equals(right)){ return right; } } throw new EvaluationException("No PMML data type for the intersection of PMML data types " + left.value() + " and " + right.value()); } private  TypeUtil(); }
TypeUtil { static public DataType getCommonDataType(DataType left, DataType right){ if((left).equals(right)){ switch(left){ case DOUBLE: case FLOAT: case INTEGER: return left; default: break; } } else if((DataType.DOUBLE).equals(left)){ if((DataType.FLOAT).equals(right) || (DataType.INTEGER).equals(right)){ return left; } } else if((DataType.FLOAT).equals(left)){ if((DataType.DOUBLE).equals(right)){ return right; } else if((DataType.INTEGER).equals(right)){ return left; } } else if((DataType.INTEGER).equals(left)){ if((DataType.DOUBLE).equals(right) || (DataType.FLOAT).equals(right)){ return right; } } throw new EvaluationException("No PMML data type for the intersection of PMML data types " + left.value() + " and " + right.value()); } private  TypeUtil(); static String format(Object value); static Object parseOrCast(DataType dataType, Object value); static Object parse(DataType dataType, String value); static DaysSinceDate parseDaysSinceDate(LocalDate epoch, String value); static boolean equals(DataType dataType, Object value, Object referenceValue); static DataType getDataType(Object value); static DataType getDataType(Collection<?> values); static DataType getCommonDataType(DataType left, DataType right); static OpType getOpType(DataType dataType); static Object cast(DataType dataType, Object value); static V cast(Class<? extends V> clazz, Object value); static DataType getConstantDataType(Object value); static DataType getConstantDataType(String value); }
TypeUtil { static public DataType getCommonDataType(DataType left, DataType right){ if((left).equals(right)){ switch(left){ case DOUBLE: case FLOAT: case INTEGER: return left; default: break; } } else if((DataType.DOUBLE).equals(left)){ if((DataType.FLOAT).equals(right) || (DataType.INTEGER).equals(right)){ return left; } } else if((DataType.FLOAT).equals(left)){ if((DataType.DOUBLE).equals(right)){ return right; } else if((DataType.INTEGER).equals(right)){ return left; } } else if((DataType.INTEGER).equals(left)){ if((DataType.DOUBLE).equals(right) || (DataType.FLOAT).equals(right)){ return right; } } throw new EvaluationException("No PMML data type for the intersection of PMML data types " + left.value() + " and " + right.value()); } private  TypeUtil(); static String format(Object value); static Object parseOrCast(DataType dataType, Object value); static Object parse(DataType dataType, String value); static DaysSinceDate parseDaysSinceDate(LocalDate epoch, String value); static boolean equals(DataType dataType, Object value, Object referenceValue); static DataType getDataType(Object value); static DataType getDataType(Collection<?> values); static DataType getCommonDataType(DataType left, DataType right); static OpType getOpType(DataType dataType); static Object cast(DataType dataType, Object value); static V cast(Class<? extends V> clazz, Object value); static DataType getConstantDataType(Object value); static DataType getConstantDataType(String value);  }