Numbers { @Nullable public static Double parseDoubleNull(@Nullable String str) { if (str == null || str.isEmpty()) { return null; } else { try { final double value = Double.parseDouble(str); if (Double.isNaN(value) || Double.isInfinite(value)) { return null; } else { return value; } } catch (NumberFormatException e) { return null; } } }  static boolean isReal(double value); static int pow(int x, int y); static double parseDouble(@Nullable String str); @Nullable static Double parseDoubleNull(@Nullable String str); static float parseFloat(@Nullable String str); static int parseInt(@Nullable String str, int defaultValue); static final DecimalFormat format2; static final DecimalFormat format3; static final DecimalFormat format6; }
@Test public void parseDoubleNull() { assertEquals(-2, Numbers.parseDoubleNull("-2"), 0.1); assertEquals(-1, Numbers.parseDoubleNull("-1"), 0.1); assertEquals(0, Numbers.parseDoubleNull("0"), 0.1); assertEquals(1, Numbers.parseDoubleNull("1"), 0.1); assertEquals(2, Numbers.parseDoubleNull("2"), 0.1); assertNull(Numbers.parseDoubleNull("")); assertEquals(0.0, Numbers.parseDoubleNull("0.0"), 0.1); assertEquals(0.1, Numbers.parseDoubleNull("0.1"), 0.1); assertNull(Numbers.parseDoubleNull("X")); assertNull(Numbers.parseDoubleNull("NaN")); assertNull(Numbers.parseDoubleNull(null)); }