@Test public void testGetAsIntegerReplaceWithDefault() { field.set("BAD"); int result = FieldValueTool.getAsInteger(field::get, 123); assertEquals(123, result); }
public static int getAsInteger(final Supplier<String> fieldGetter, final int defaultValue) { String text = fieldGetter.get(); try { return Integer.parseInt(text); } catch (final NumberFormatException e) { LOG.debug("Illegal field value", e); return defaultValue; } }
FieldValueTool { public static int getAsInteger(final Supplier<String> fieldGetter, final int defaultValue) { String text = fieldGetter.get(); try { return Integer.parseInt(text); } catch (final NumberFormatException e) { LOG.debug("Illegal field value", e); return defaultValue; } } }
FieldValueTool { public static int getAsInteger(final Supplier<String> fieldGetter, final int defaultValue) { String text = fieldGetter.get(); try { return Integer.parseInt(text); } catch (final NumberFormatException e) { LOG.debug("Illegal field value", e); return defaultValue; } } private  FieldValueTool(); }
FieldValueTool { public static int getAsInteger(final Supplier<String> fieldGetter, final int defaultValue) { String text = fieldGetter.get(); try { return Integer.parseInt(text); } catch (final NumberFormatException e) { LOG.debug("Illegal field value", e); return defaultValue; } } private  FieldValueTool(); static int getAsInteger(final Supplier<String> fieldGetter, final int defaultValue); static void applyDefaultIfEmpty(final Consumer<String> fieldSetter, final Supplier<String> fieldGetter, final Supplier<Object> defaultGetter); static void cleanNonNegativeInteger(final Consumer<String> fieldSetter, final String newValue, final String oldValue); }
FieldValueTool { public static int getAsInteger(final Supplier<String> fieldGetter, final int defaultValue) { String text = fieldGetter.get(); try { return Integer.parseInt(text); } catch (final NumberFormatException e) { LOG.debug("Illegal field value", e); return defaultValue; } } private  FieldValueTool(); static int getAsInteger(final Supplier<String> fieldGetter, final int defaultValue); static void applyDefaultIfEmpty(final Consumer<String> fieldSetter, final Supplier<String> fieldGetter, final Supplier<Object> defaultGetter); static void cleanNonNegativeInteger(final Consumer<String> fieldSetter, final String newValue, final String oldValue);  }