@Test public void parseInteger(){ assertEquals(0, TypeUtil.parse(DataType.INTEGER, "-0")); assertEquals(0, TypeUtil.parse(DataType.INTEGER, "0")); assertEquals(1, TypeUtil.parse(DataType.INTEGER, "1")); assertEquals(1, TypeUtil.parse(DataType.INTEGER, "1.0")); assertEquals(1, TypeUtil.parse(DataType.INTEGER, "1e+0")); assertEquals(1, TypeUtil.parse(DataType.INTEGER, "1.0e+0")); assertEquals(0, TypeUtil.parse(DataType.INTEGER, "false")); assertEquals(1, TypeUtil.parse(DataType.INTEGER, "true")); assertEquals(Integer.MIN_VALUE, TypeUtil.parse(DataType.INTEGER, Integer.toString(Integer.MIN_VALUE))); try { TypeUtil.parse(DataType.INTEGER, Long.toString(Integer.MIN_VALUE - 1l)); fail(); } catch(IllegalArgumentException iae){ } try { TypeUtil.parse(DataType.INTEGER, Double.toString(Integer.MIN_VALUE - 1d)); fail(); } catch(IllegalArgumentException iae){ } assertEquals(Integer.MAX_VALUE, TypeUtil.parse(DataType.INTEGER, Integer.toString(Integer.MAX_VALUE))); try { TypeUtil.parse(DataType.INTEGER, Long.toString(Integer.MAX_VALUE + 1l)); fail(); } catch(IllegalArgumentException iae){ } try { TypeUtil.parse(DataType.INTEGER, Double.toString(Integer.MAX_VALUE + 1d)); fail(); } catch(IllegalArgumentException iae){ } }
static private Integer parseInteger(String value){ try { long result = Long.parseLong(value); return parseInteger(value, result); } catch(NumberFormatException nfeInteger){ try { double result = Double.parseDouble(value); if(DoubleMath.isMathematicalInteger(result)){ return parseInteger(value, (long)result); } } catch(NumberFormatException nfeDouble){ } try { return toInteger(parseFlag(value)); } catch(IllegalArgumentException iae){ } throw nfeInteger; } }
TypeUtil { static private Integer parseInteger(String value){ try { long result = Long.parseLong(value); return parseInteger(value, result); } catch(NumberFormatException nfeInteger){ try { double result = Double.parseDouble(value); if(DoubleMath.isMathematicalInteger(result)){ return parseInteger(value, (long)result); } } catch(NumberFormatException nfeDouble){ } try { return toInteger(parseFlag(value)); } catch(IllegalArgumentException iae){ } throw nfeInteger; } } }
TypeUtil { static private Integer parseInteger(String value){ try { long result = Long.parseLong(value); return parseInteger(value, result); } catch(NumberFormatException nfeInteger){ try { double result = Double.parseDouble(value); if(DoubleMath.isMathematicalInteger(result)){ return parseInteger(value, (long)result); } } catch(NumberFormatException nfeDouble){ } try { return toInteger(parseFlag(value)); } catch(IllegalArgumentException iae){ } throw nfeInteger; } } private  TypeUtil(); }
TypeUtil { static private Integer parseInteger(String value){ try { long result = Long.parseLong(value); return parseInteger(value, result); } catch(NumberFormatException nfeInteger){ try { double result = Double.parseDouble(value); if(DoubleMath.isMathematicalInteger(result)){ return parseInteger(value, (long)result); } } catch(NumberFormatException nfeDouble){ } try { return toInteger(parseFlag(value)); } catch(IllegalArgumentException iae){ } throw nfeInteger; } } private  TypeUtil(); static String format(Object value); static Object parseOrCast(DataType dataType, Object value); static Object parse(DataType dataType, String value); static DaysSinceDate parseDaysSinceDate(LocalDate epoch, String value); static boolean equals(DataType dataType, Object value, Object referenceValue); static DataType getDataType(Object value); static DataType getDataType(Collection<?> values); static DataType getCommonDataType(DataType left, DataType right); static OpType getOpType(DataType dataType); static Object cast(DataType dataType, Object value); static V cast(Class<? extends V> clazz, Object value); static DataType getConstantDataType(Object value); static DataType getConstantDataType(String value); }
TypeUtil { static private Integer parseInteger(String value){ try { long result = Long.parseLong(value); return parseInteger(value, result); } catch(NumberFormatException nfeInteger){ try { double result = Double.parseDouble(value); if(DoubleMath.isMathematicalInteger(result)){ return parseInteger(value, (long)result); } } catch(NumberFormatException nfeDouble){ } try { return toInteger(parseFlag(value)); } catch(IllegalArgumentException iae){ } throw nfeInteger; } } private  TypeUtil(); static String format(Object value); static Object parseOrCast(DataType dataType, Object value); static Object parse(DataType dataType, String value); static DaysSinceDate parseDaysSinceDate(LocalDate epoch, String value); static boolean equals(DataType dataType, Object value, Object referenceValue); static DataType getDataType(Object value); static DataType getDataType(Collection<?> values); static DataType getCommonDataType(DataType left, DataType right); static OpType getOpType(DataType dataType); static Object cast(DataType dataType, Object value); static V cast(Class<? extends V> clazz, Object value); static DataType getConstantDataType(Object value); static DataType getConstantDataType(String value);  }