@Test public void testGetArithmaticType() { try { StreamClassUtil.getArithmaticType(boolean.class, int.class); fail(); } catch (IllegalDataTypeException e) { Assert.assertTrue(true); } try { Assert.assertEquals(Integer.class, StreamClassUtil.getArithmaticType(int.class, int.class)); Assert.assertEquals(Integer.class, StreamClassUtil.getArithmaticType(int.class, Integer.class)); Assert.assertEquals(Integer.class, StreamClassUtil.getArithmaticType(Integer.class, Integer.class)); Assert.assertEquals(Long.class, StreamClassUtil.getArithmaticType(int.class, Long.class)); Assert.assertEquals(Long.class, StreamClassUtil.getArithmaticType(Integer.class, long.class)); Assert.assertEquals(Double.class, StreamClassUtil.getArithmaticType(int.class, Double.class)); Assert.assertEquals(Double.class, StreamClassUtil.getArithmaticType(Integer.class, double.class)); Assert.assertEquals(Float.class, StreamClassUtil.getArithmaticType(int.class, Float.class)); Assert.assertEquals(Float.class, StreamClassUtil.getArithmaticType(Integer.class, float.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getArithmaticType(int.class, BigDecimal.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getArithmaticType(Integer.class, BigDecimal.class)); Assert.assertEquals(Long.class, StreamClassUtil.getArithmaticType(long.class, long.class)); Assert.assertEquals(Long.class, StreamClassUtil.getArithmaticType(Long.class, Long.class)); Assert.assertEquals(Double.class, StreamClassUtil.getArithmaticType(long.class, Double.class)); Assert.assertEquals(Double.class, StreamClassUtil.getArithmaticType(Long.class, double.class)); Assert.assertEquals(Float.class, StreamClassUtil.getArithmaticType(long.class, Float.class)); Assert.assertEquals(Float.class, StreamClassUtil.getArithmaticType(Long.class, float.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getArithmaticType(long.class, BigDecimal.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getArithmaticType(Long.class, BigDecimal.class)); Assert.assertEquals(Float.class, StreamClassUtil.getArithmaticType(float.class, Float.class)); Assert.assertEquals(Float.class, StreamClassUtil.getArithmaticType(Float.class, Float.class)); Assert.assertEquals(Double.class, StreamClassUtil.getArithmaticType(float.class, Double.class)); Assert.assertEquals(Double.class, StreamClassUtil.getArithmaticType(Float.class, double.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getArithmaticType(float.class, BigDecimal.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getArithmaticType(Float.class, BigDecimal.class)); Assert.assertEquals(Double.class, StreamClassUtil.getArithmaticType(double.class, Double.class)); Assert.assertEquals(Double.class, StreamClassUtil.getArithmaticType(Double.class, Double.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getArithmaticType(double.class, BigDecimal.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getArithmaticType(Double.class, BigDecimal.class)); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getArithmaticType(BigDecimal.class, BigDecimal.class)); Assert.assertTrue(true); } catch (IllegalDataTypeException e) { fail(); } }
public static Class< ? > getArithmaticType(Class< ? > leftType, Class< ? > rightType) throws IllegalDataTypeException { Class< ? > leftWarp = getWrapType(leftType); Class< ? > rightWarp = getWrapType(rightType); if (!isNumberic(leftWarp) || !isNumberic(rightWarp)) { LOG.error("Can't infer result type from {} and {}.", leftType.getName(), rightType.getName()); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.SEMANTICANALYZE_ARITHMETIC_EXPRESSION_NUMBER_TYPE); throw exp; } if (leftWarp == rightWarp) { return leftWarp; } if ((leftWarp == BigDecimal.class) || (rightWarp == BigDecimal.class)) { return BigDecimal.class; } if (leftWarp == Double.class || rightWarp == Double.class) { return Double.class; } if (leftWarp == Float.class || rightWarp == Float.class) { return Float.class; } if (leftWarp == Long.class || rightWarp == Long.class) { return Long.class; } return Integer.class; }
StreamClassUtil { public static Class< ? > getArithmaticType(Class< ? > leftType, Class< ? > rightType) throws IllegalDataTypeException { Class< ? > leftWarp = getWrapType(leftType); Class< ? > rightWarp = getWrapType(rightType); if (!isNumberic(leftWarp) || !isNumberic(rightWarp)) { LOG.error("Can't infer result type from {} and {}.", leftType.getName(), rightType.getName()); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.SEMANTICANALYZE_ARITHMETIC_EXPRESSION_NUMBER_TYPE); throw exp; } if (leftWarp == rightWarp) { return leftWarp; } if ((leftWarp == BigDecimal.class) || (rightWarp == BigDecimal.class)) { return BigDecimal.class; } if (leftWarp == Double.class || rightWarp == Double.class) { return Double.class; } if (leftWarp == Float.class || rightWarp == Float.class) { return Float.class; } if (leftWarp == Long.class || rightWarp == Long.class) { return Long.class; } return Integer.class; } }
StreamClassUtil { public static Class< ? > getArithmaticType(Class< ? > leftType, Class< ? > rightType) throws IllegalDataTypeException { Class< ? > leftWarp = getWrapType(leftType); Class< ? > rightWarp = getWrapType(rightType); if (!isNumberic(leftWarp) || !isNumberic(rightWarp)) { LOG.error("Can't infer result type from {} and {}.", leftType.getName(), rightType.getName()); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.SEMANTICANALYZE_ARITHMETIC_EXPRESSION_NUMBER_TYPE); throw exp; } if (leftWarp == rightWarp) { return leftWarp; } if ((leftWarp == BigDecimal.class) || (rightWarp == BigDecimal.class)) { return BigDecimal.class; } if (leftWarp == Double.class || rightWarp == Double.class) { return Double.class; } if (leftWarp == Float.class || rightWarp == Float.class) { return Float.class; } if (leftWarp == Long.class || rightWarp == Long.class) { return Long.class; } return Integer.class; }  }
StreamClassUtil { public static Class< ? > getArithmaticType(Class< ? > leftType, Class< ? > rightType) throws IllegalDataTypeException { Class< ? > leftWarp = getWrapType(leftType); Class< ? > rightWarp = getWrapType(rightType); if (!isNumberic(leftWarp) || !isNumberic(rightWarp)) { LOG.error("Can't infer result type from {} and {}.", leftType.getName(), rightType.getName()); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.SEMANTICANALYZE_ARITHMETIC_EXPRESSION_NUMBER_TYPE); throw exp; } if (leftWarp == rightWarp) { return leftWarp; } if ((leftWarp == BigDecimal.class) || (rightWarp == BigDecimal.class)) { return BigDecimal.class; } if (leftWarp == Double.class || rightWarp == Double.class) { return Double.class; } if (leftWarp == Float.class || rightWarp == Float.class) { return Float.class; } if (leftWarp == Long.class || rightWarp == Long.class) { return Long.class; } return Integer.class; }  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); }
StreamClassUtil { public static Class< ? > getArithmaticType(Class< ? > leftType, Class< ? > rightType) throws IllegalDataTypeException { Class< ? > leftWarp = getWrapType(leftType); Class< ? > rightWarp = getWrapType(rightType); if (!isNumberic(leftWarp) || !isNumberic(rightWarp)) { LOG.error("Can't infer result type from {} and {}.", leftType.getName(), rightType.getName()); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.SEMANTICANALYZE_ARITHMETIC_EXPRESSION_NUMBER_TYPE); throw exp; } if (leftWarp == rightWarp) { return leftWarp; } if ((leftWarp == BigDecimal.class) || (rightWarp == BigDecimal.class)) { return BigDecimal.class; } if (leftWarp == Double.class || rightWarp == Double.class) { return Double.class; } if (leftWarp == Float.class || rightWarp == Float.class) { return Float.class; } if (leftWarp == Long.class || rightWarp == Long.class) { return Long.class; } return Integer.class; }  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);  }