@Test public void testGetCommonType() { List<Class< ? >> list = Lists.newArrayList(); try { StreamClassUtil.getCommonType(null); fail(); } catch (IllegalDataTypeException e) { Assert.assertTrue(true); } try { StreamClassUtil.getCommonType(list); fail(); } catch (IllegalDataTypeException e) { Assert.assertTrue(true); } try { list.clear(); list.add(boolean.class); Assert.assertEquals(Boolean.class, StreamClassUtil.getCommonType(list)); list.add(Boolean.class); Assert.assertEquals(Boolean.class, StreamClassUtil.getCommonType(list)); } catch (IllegalDataTypeException e) { fail(); } try { list.clear(); list.add(boolean.class); list.add(String.class); Assert.assertEquals(Boolean.class, StreamClassUtil.getCommonType(list)); fail(); } catch (IllegalDataTypeException e) { Assert.assertTrue(true); } try { list.clear(); list.add(String.class); Assert.assertEquals(String.class, StreamClassUtil.getCommonType(list)); list.add(String.class); Assert.assertEquals(String.class, StreamClassUtil.getCommonType(list)); } catch (IllegalDataTypeException e) { fail(); } try { list.clear(); list.add(String.class); list.add(int.class); Assert.assertEquals(String.class, StreamClassUtil.getCommonType(list)); fail(); } catch (IllegalDataTypeException e) { Assert.assertTrue(true); } try { list.clear(); list.add(int.class); Assert.assertEquals(Integer.class, StreamClassUtil.getCommonType(list)); list.add(Integer.class); Assert.assertEquals(Integer.class, StreamClassUtil.getCommonType(list)); list.add(long.class); Assert.assertEquals(Long.class, StreamClassUtil.getCommonType(list)); list.add(Float.class); Assert.assertEquals(Float.class, StreamClassUtil.getCommonType(list)); list.add(double.class); Assert.assertEquals(Double.class, StreamClassUtil.getCommonType(list)); list.add(BigDecimal.class); Assert.assertEquals(BigDecimal.class, StreamClassUtil.getCommonType(list)); } catch (IllegalDataTypeException e) { fail(); } try { list.clear(); list.add(int.class); list.add(Integer.class); list.add(String.class); Assert.assertEquals(Integer.class, StreamClassUtil.getCommonType(list)); fail(); } catch (IllegalDataTypeException e) { Assert.assertTrue(true); } }
public static Class< ? > getCommonType(List<Class< ? >> childTypes) throws IllegalDataTypeException { if (childTypes == null || childTypes.size() < 1) { LOG.error("Child Types must have one."); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } int childSize = childTypes.size(); if (childSize == 1) { return getWrapType(childTypes.get(0)); } List<Class< ? >> wrapTypes = new LinkedList<Class< ? >>(); for (int i = 0; i < childSize; i++) { if (childTypes.get(i) != null) { wrapTypes.add(getWrapType(childTypes.get(i))); } } int wrapSize = wrapTypes.size(); if (wrapSize == 0) { return null; } if (wrapSize == 1) { return wrapTypes.get(0); } if (wrapTypes.get(0) == String.class) { for (int i = 0; i < wrapSize; i++) { if (wrapTypes.get(i) != String.class) { LOG.error("Can't infer result type from {} and {}.", childTypes.get(i), String.class); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } } return String.class; } if (wrapTypes.get(0) == Boolean.class) { for (int i = 0; i < wrapSize; i++) { if (wrapTypes.get(i) != Boolean.class) { LOG.error("Can't infer result type from {} and {}.", childTypes.get(i), Boolean.class); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } } return Boolean.class; } Class< ? > result = getArithmaticType(wrapTypes.get(0), wrapTypes.get(1)); int count = COUNT_INIT; while (count < wrapSize) { result = getArithmaticType(result, wrapTypes.get(count)); count++; } return result; }
StreamClassUtil { public static Class< ? > getCommonType(List<Class< ? >> childTypes) throws IllegalDataTypeException { if (childTypes == null || childTypes.size() < 1) { LOG.error("Child Types must have one."); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } int childSize = childTypes.size(); if (childSize == 1) { return getWrapType(childTypes.get(0)); } List<Class< ? >> wrapTypes = new LinkedList<Class< ? >>(); for (int i = 0; i < childSize; i++) { if (childTypes.get(i) != null) { wrapTypes.add(getWrapType(childTypes.get(i))); } } int wrapSize = wrapTypes.size(); if (wrapSize == 0) { return null; } if (wrapSize == 1) { return wrapTypes.get(0); } if (wrapTypes.get(0) == String.class) { for (int i = 0; i < wrapSize; i++) { if (wrapTypes.get(i) != String.class) { LOG.error("Can't infer result type from {} and {}.", childTypes.get(i), String.class); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } } return String.class; } if (wrapTypes.get(0) == Boolean.class) { for (int i = 0; i < wrapSize; i++) { if (wrapTypes.get(i) != Boolean.class) { LOG.error("Can't infer result type from {} and {}.", childTypes.get(i), Boolean.class); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } } return Boolean.class; } Class< ? > result = getArithmaticType(wrapTypes.get(0), wrapTypes.get(1)); int count = COUNT_INIT; while (count < wrapSize) { result = getArithmaticType(result, wrapTypes.get(count)); count++; } return result; } }
StreamClassUtil { public static Class< ? > getCommonType(List<Class< ? >> childTypes) throws IllegalDataTypeException { if (childTypes == null || childTypes.size() < 1) { LOG.error("Child Types must have one."); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } int childSize = childTypes.size(); if (childSize == 1) { return getWrapType(childTypes.get(0)); } List<Class< ? >> wrapTypes = new LinkedList<Class< ? >>(); for (int i = 0; i < childSize; i++) { if (childTypes.get(i) != null) { wrapTypes.add(getWrapType(childTypes.get(i))); } } int wrapSize = wrapTypes.size(); if (wrapSize == 0) { return null; } if (wrapSize == 1) { return wrapTypes.get(0); } if (wrapTypes.get(0) == String.class) { for (int i = 0; i < wrapSize; i++) { if (wrapTypes.get(i) != String.class) { LOG.error("Can't infer result type from {} and {}.", childTypes.get(i), String.class); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } } return String.class; } if (wrapTypes.get(0) == Boolean.class) { for (int i = 0; i < wrapSize; i++) { if (wrapTypes.get(i) != Boolean.class) { LOG.error("Can't infer result type from {} and {}.", childTypes.get(i), Boolean.class); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } } return Boolean.class; } Class< ? > result = getArithmaticType(wrapTypes.get(0), wrapTypes.get(1)); int count = COUNT_INIT; while (count < wrapSize) { result = getArithmaticType(result, wrapTypes.get(count)); count++; } return result; }  }
StreamClassUtil { public static Class< ? > getCommonType(List<Class< ? >> childTypes) throws IllegalDataTypeException { if (childTypes == null || childTypes.size() < 1) { LOG.error("Child Types must have one."); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } int childSize = childTypes.size(); if (childSize == 1) { return getWrapType(childTypes.get(0)); } List<Class< ? >> wrapTypes = new LinkedList<Class< ? >>(); for (int i = 0; i < childSize; i++) { if (childTypes.get(i) != null) { wrapTypes.add(getWrapType(childTypes.get(i))); } } int wrapSize = wrapTypes.size(); if (wrapSize == 0) { return null; } if (wrapSize == 1) { return wrapTypes.get(0); } if (wrapTypes.get(0) == String.class) { for (int i = 0; i < wrapSize; i++) { if (wrapTypes.get(i) != String.class) { LOG.error("Can't infer result type from {} and {}.", childTypes.get(i), String.class); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } } return String.class; } if (wrapTypes.get(0) == Boolean.class) { for (int i = 0; i < wrapSize; i++) { if (wrapTypes.get(i) != Boolean.class) { LOG.error("Can't infer result type from {} and {}.", childTypes.get(i), Boolean.class); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } } return Boolean.class; } Class< ? > result = getArithmaticType(wrapTypes.get(0), wrapTypes.get(1)); int count = COUNT_INIT; while (count < wrapSize) { result = getArithmaticType(result, wrapTypes.get(count)); count++; } return result; }  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< ? > getCommonType(List<Class< ? >> childTypes) throws IllegalDataTypeException { if (childTypes == null || childTypes.size() < 1) { LOG.error("Child Types must have one."); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } int childSize = childTypes.size(); if (childSize == 1) { return getWrapType(childTypes.get(0)); } List<Class< ? >> wrapTypes = new LinkedList<Class< ? >>(); for (int i = 0; i < childSize; i++) { if (childTypes.get(i) != null) { wrapTypes.add(getWrapType(childTypes.get(i))); } } int wrapSize = wrapTypes.size(); if (wrapSize == 0) { return null; } if (wrapSize == 1) { return wrapTypes.get(0); } if (wrapTypes.get(0) == String.class) { for (int i = 0; i < wrapSize; i++) { if (wrapTypes.get(i) != String.class) { LOG.error("Can't infer result type from {} and {}.", childTypes.get(i), String.class); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } } return String.class; } if (wrapTypes.get(0) == Boolean.class) { for (int i = 0; i < wrapSize; i++) { if (wrapTypes.get(i) != Boolean.class) { LOG.error("Can't infer result type from {} and {}.", childTypes.get(i), Boolean.class); IllegalDataTypeException exp = new IllegalDataTypeException(ErrorCode.UNKNOWN_SERVER_COMMON_ERROR); throw exp; } } return Boolean.class; } Class< ? > result = getArithmaticType(wrapTypes.get(0), wrapTypes.get(1)); int count = COUNT_INIT; while (count < wrapSize) { result = getArithmaticType(result, wrapTypes.get(count)); count++; } return result; }  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);  }