EvaluationUtil implements Serializable { public static Object castTo(Object x, TypeInformation t) { if (x == null) { return null; } else if (t.equals(Types.BOOLEAN)) { if (x instanceof Boolean) { return x; } return Boolean.valueOf(x.toString()); } else if (t.equals(Types.BYTE)) { if (x instanceof Number) { return ((Number)x).byteValue(); } return Byte.valueOf(x.toString()); } else if (t.equals(Types.SHORT)) { if (x instanceof Number) { return ((Number)x).shortValue(); } return Short.valueOf(x.toString()); } else if (t.equals(Types.INT)) { if (x instanceof Number) { return ((Number)x).intValue(); } return Integer.valueOf(x.toString()); } else if (t.equals(Types.LONG)) { if (x instanceof Number) { return ((Number)x).longValue(); } return Long.valueOf(x.toString()); } else if (t.equals(Types.FLOAT)) { if (x instanceof Number) { return ((Number)x).floatValue(); } return Float.valueOf(x.toString()); } else if (t.equals(Types.DOUBLE)) { if (x instanceof Number) { return ((Number)x).doubleValue(); } return Double.valueOf(x.toString()); } else if (t.equals(Types.STRING)) { if (x instanceof String) { return x; } return x.toString(); } else { throw new RuntimeException("unsupported type: " + t.getClass().getName()); } }  static boolean labelCompare(Object label1, Object label2, TypeInformation type); static int compare(Object o1, Object o2); static Object castTo(Object x, TypeInformation t); static BaseMetricsSummary getDetailStatistics(Iterable<Row> rows, String positiveValue, boolean binary, TypeInformation labelType); static BaseMetricsSummary getDetailStatistics(Iterable<Row> rows,
                                                         boolean binary,
                                                         Tuple2<Map<Object, Integer>, Object[]> labels,
                                                         TypeInformation labelType); static boolean checkRowFieldNotNull(Row row); static double extractLogloss(TreeMap<Object, Double> labelProbMap, Object label); static TreeMap<Object, Double> extractLabelProbMap(Row row, TypeInformation labelType); static void updateBinaryMetricsSummary(TreeMap<Object, Double> labelProbMap,
                                                  Object label,
                                                  BinaryMetricsSummary binaryMetricsSummary); static void updateMultiMetricsSummary(TreeMap<Object, Double> labelProbMap,
                                                 Object label,
                                                 Map<Object, Integer> labels,
                                                 MultiMetricsSummary multiMetricsSummary); static RegressionMetricsSummary getRegressionStatistics(Iterable<Row> rows); static MultiMetricsSummary getMultiClassMetrics(Iterable<Row> rows,
                                                           Tuple2<Map<Object, Integer>, Object[]>
                                                               labelIndexLabelArray);  }
@Test public void testCastTo(){ Assert.assertTrue(EvaluationUtil.castTo("true", Types.BOOLEAN) instanceof Boolean); Assert.assertTrue(EvaluationUtil.castTo(true, Types.BOOLEAN) instanceof Boolean); Assert.assertTrue(EvaluationUtil.castTo("1", Types.SHORT) instanceof Short); Assert.assertTrue(EvaluationUtil.castTo((short)1, Types.SHORT) instanceof Short); Assert.assertTrue(EvaluationUtil.castTo("1", Types.INT) instanceof Integer); Assert.assertTrue(EvaluationUtil.castTo(1, Types.INT) instanceof Integer); Assert.assertTrue(EvaluationUtil.castTo("1", Types.LONG) instanceof Long); Assert.assertTrue(EvaluationUtil.castTo(1L, Types.LONG) instanceof Long); Assert.assertTrue(EvaluationUtil.castTo("1", Types.BYTE) instanceof Byte); Assert.assertTrue(EvaluationUtil.castTo((byte)1, Types.BYTE) instanceof Byte); Assert.assertTrue(EvaluationUtil.castTo("1", Types.FLOAT) instanceof Float); Assert.assertTrue(EvaluationUtil.castTo((float)1, Types.FLOAT) instanceof Float); Assert.assertTrue(EvaluationUtil.castTo("1", Types.DOUBLE) instanceof Double); Assert.assertTrue(EvaluationUtil.castTo((double)1, Types.DOUBLE) instanceof Double); Assert.assertTrue(EvaluationUtil.castTo("1", Types.STRING) instanceof String); thrown.expect(RuntimeException.class); thrown.expectMessage("unsupported type: org.apache.flink.api.common.typeinfo.BasicTypeInfo"); EvaluationUtil.castTo("1", Types.BIG_DEC); }