StreamClassUtil { public static Class< ? > getCompareType(Class< ? > typeOne, Class< ? > typeTwo) throws IllegalDataTypeException { if ((typeOne == String.class) && (typeTwo == String.class)) { return String.class; } if (((typeOne == boolean.class) || ((typeOne == Boolean.class))) && ((typeTwo == boolean.class) || ((typeTwo == Boolean.class)))) { return Boolean.class; } if (typeOne == null) { return typeTwo; } if (typeTwo == null) { return typeOne; } if (!isNumberic(typeOne) || !isNumberic(typeTwo)) { String typeOneName = typeOne.getName(); String typeTwoName = typeTwo.getName(); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.SEMANTICANALYZE_EXPRESSION_DATATYPE_COMPARE, typeOneName, typeTwoName); LOG.error(exp.getMessage(), exp); throw exp; } return getArithmaticType(typeOne, typeTwo); }  static Class< ? > getWrapType(Class< ? > type); static boolean isNumberic(Class< ? > type); static Class< ? > getArithmaticType(Class< ? > leftType, Class< ? > rightType); static Class< ? > getCommonType(List<Class< ? >> childTypes); static Number getNumbericValueForType(Number result, Class< ? > resultType); static BigDecimal getBigDecimalValue(Number result); static boolean isFloatingPointNumber(Number value); static Class< ? > getCompareType(Class< ? > typeOne, Class< ? > typeTwo); static boolean isBoolean(Class< ? > type); static boolean isDateOrTimestamp(Class< ? > type);  }
@Test public void testGetCompareType() { try { Assert.assertEquals(String.class, StreamClassUtil.getCompareType(String.class, String.class)); Assert.assertEquals(Boolean.class, StreamClassUtil.getCompareType(boolean.class, Boolean.class)); } catch (IllegalDataTypeException e) { fail(); } try { Assert.assertEquals(Integer.class, StreamClassUtil.getCompareType(String.class, Integer.class)); fail(); } catch (IllegalDataTypeException e) { Assert.assertTrue(true); } try { Assert.assertEquals(Integer.class, StreamClassUtil.getCompareType(int.class, Integer.class)); Assert.assertEquals(Long.class, StreamClassUtil.getCompareType(long.class, Integer.class)); Assert.assertEquals(Float.class, StreamClassUtil.getCompareType(float.class, Integer.class)); Assert.assertEquals(Double.class, StreamClassUtil.getCompareType(double.class, Integer.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getCompareType(BigDecimal.class, Integer.class)); Assert.assertEquals(Long.class, StreamClassUtil.getCompareType(long.class, Long.class)); Assert.assertEquals(Float.class, StreamClassUtil.getCompareType(float.class, Long.class)); Assert.assertEquals(Double.class, StreamClassUtil.getCompareType(double.class, Long.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getCompareType(BigDecimal.class, Long.class)); Assert.assertEquals(Float.class, StreamClassUtil.getCompareType(float.class, Float.class)); Assert.assertEquals(Double.class, StreamClassUtil.getCompareType(double.class, Float.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getCompareType(BigDecimal.class, Float.class)); Assert.assertEquals(Double.class, StreamClassUtil.getCompareType(double.class, Double.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getCompareType(BigDecimal.class, Double.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getCompareType(BigDecimal.class, BigDecimal.class)); } catch (IllegalDataTypeException e) { fail(); } }