TypeInferenceUtils { public static boolean isDouble(String value) { if (!isEmpty(value) && patternDouble.matcher(value).matches()) { return true; } return false; }  static boolean isDouble(String value); static boolean isInteger(String value); static boolean isNumber(String value); static BigInteger getBigInteger(String value); static boolean isBoolean(String value); static boolean isDate(String value); static boolean isTime(String value); static boolean isEmpty(String value); static boolean isValid(DataTypeEnum type, String value); static DataTypeEnum getDataType(String value); static DataTypeEnum getNativeDataType(String value);  }
@Test public void testIsDouble() { String[] validEnDoubleValues = { "0.8", "1.2", "100", "100.0", "-2.0", "1.0e-04", "1.0e+4", "1E-4", "1.0 e-4", "1 E+12", "25%", "589.94 %", "1.65E-5%" }; String[] validFrDoubleValues = { "0,9", "1,0e-4", "8,9568%" }; String[] invalidDoubleValues = { "NaN", "3.4d", "123L", "123l", " 0.8", "0.8 ", "0. 8", "1. 0e-4", "1.0e -4", "3%4", "8%E6", "123%.4" }; for (String value : (String[]) ArrayUtils.addAll(validEnDoubleValues, validFrDoubleValues)) { Assert.assertTrue(value + " is expected to be a valid decimal value but actually not.", TypeInferenceUtils.isDouble(value)); } for (String value : invalidDoubleValues) { Assert.assertFalse(value + " is expected to be an invalid decimal value but actually not.", TypeInferenceUtils.isDouble(value)); } }
@Test public void testIsDecimal() { String[] validEnDoubleValues = { "5538297118", "1045.35", "1,045.35", "1,045", "1,045,350", "2.68435E+17", "268 435 000 000 000 000", "265" + '\u00A0' + "435" + '\u2007' + "000" + '\u202F' + "000" }; String[] validFrDoubleValues = { "1045,35", "1 045,35", "1.045,35", "1.045", "1 045", "1.045.350", "1 045 350" }; String[] invalidDoubleValues = { "1 045.35", "1.045.35", "1,045,35", "1,045 35", "1.045 35", "1,045 350", "1.045 350", "1 045 35" }; for (String value : validEnDoubleValues) { Assert.assertTrue(value + " is expected to be a valid decimal value but actually not.", TypeInferenceUtils.isDouble(value)); } for (String value : validFrDoubleValues) { Assert.assertTrue(value + " is expected to be a valid decimal value but actually not.", TypeInferenceUtils.isDouble(value)); } for (String value : invalidDoubleValues) { Assert.assertFalse(value + " is expected to be an invalid decimal value but actually not.", TypeInferenceUtils.isDouble(value)); } }
@Test public void testPerformanceIsDouble() throws Exception { List<String> values = loadData("testDouble.csv"); int countOfDoubles = 0; long timeStart = System.currentTimeMillis(); Assert.assertEquals(10000, values.size()); for (String value : values) { if (TypeInferenceUtils.isDouble(value)) { countOfDoubles++; } } long timeEnd = System.currentTimeMillis(); Assert.assertEquals(5002, countOfDoubles); long difference = timeEnd - timeStart; LOGGER.debug("The method isDouble spent " + difference + " ms on 10000 values."); }