Numbers { public static int parseInt(@Nullable String str, int defaultValue) { if (str == null || str.isEmpty()) { return defaultValue; } else { try { return Integer.parseInt(str); } catch (NumberFormatException e) { Exceptions.report(e); return defaultValue; } } }  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 parseInt() { assertEquals(-2, Numbers.parseInt("-2", -1)); assertEquals(-1, Numbers.parseInt("-1", -1)); assertEquals(0, Numbers.parseInt("0", -1)); assertEquals(1, Numbers.parseInt("1", -1)); assertEquals(2, Numbers.parseInt("2", -1)); assertEquals(-1, Numbers.parseInt("", -1)); assertEquals(-1, Numbers.parseInt("X", -1)); assertEquals(-1, Numbers.parseInt(null, -1)); }