private static Integer parseInteger(String value) { try { return Integer.valueOf(value); } catch (NumberFormatException nfeInteger) { try { Double result = parseDouble(value); if (DoubleMath.isMathematicalInteger(result)) { return result.intValue(); } } catch (NumberFormatException nfeDouble) { // Ignored } throw nfeInteger; } }
public void testIsMathematicalIntegerNotFinite() { for (double d : Arrays.asList(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN)) { assertFalse(DoubleMath.isMathematicalInteger(d)); } }
public void testIsMathematicalIntegerFractional() { for (double d : FRACTIONAL_DOUBLE_CANDIDATES) { assertFalse(DoubleMath.isMathematicalInteger(d)); } }
public void testIsMathematicalIntegerIntegral() { for (double d : INTEGRAL_DOUBLE_CANDIDATES) { assertTrue(DoubleMath.isMathematicalInteger(d)); } }