DataTypeUtils { public static boolean typeIsNumber(DataType type) { if (type == null) { return false; } SQLType sqlType = type.getSqlType(); if (sqlType != null) { if (sqlType instanceof JDBCType) switch (((JDBCType) sqlType)) { case NUMERIC: case DECIMAL: case BIT: case BIGINT: case INTEGER: case TINYINT: case FLOAT: case DOUBLE: return true; } } if (type.getJavaType() != null) { Class<?> clazz = type.getJavaType(); if (Number.class.isAssignableFrom(clazz)) { return true; } switch (clazz.getSimpleName()) { case "byte": case "short": case "int": case "float": case "double": case "long": return true; } } return false; }  static boolean typeIsDate(DataType type); static boolean typeIsNumber(DataType type);  }
@Test public void testNumberByJavaType() { assertFalse(typeIsNumber(null)); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, byte.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, short.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, int.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, float.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, double.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, long.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, Byte.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, Short.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, Integer.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, Float.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, Double.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, Long.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, BigDecimal.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.OTHER, BigInteger.class))); assertFalse(typeIsNumber(DataType.jdbc(JDBCType.OTHER, String.class))); }
@Test public void testNumberByJdbcType() { assertFalse(typeIsNumber(null)); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.NUMERIC, String.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.INTEGER, String.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.BIGINT, String.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.DOUBLE, String.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.FLOAT, String.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.DECIMAL, String.class))); assertTrue(typeIsNumber(DataType.jdbc(JDBCType.BIT, String.class))); assertFalse(typeIsNumber(DataType.jdbc(JDBCType.DATE, String.class))); }