@Test public void testApplyDefaultIfEmptyWithValue() { field.set("123"); FieldValueTool.applyDefaultIfEmpty(field::set, field::get, () -> 0); assertEquals("123", field.get()); }
public static void applyDefaultIfEmpty(final Consumer<String> fieldSetter, final Supplier<String> fieldGetter, final Supplier<Object> defaultGetter) { String text = fieldGetter.get(); if (text.isEmpty()) { fieldSetter.accept(defaultGetter.get().toString()); } }
FieldValueTool { public static void applyDefaultIfEmpty(final Consumer<String> fieldSetter, final Supplier<String> fieldGetter, final Supplier<Object> defaultGetter) { String text = fieldGetter.get(); if (text.isEmpty()) { fieldSetter.accept(defaultGetter.get().toString()); } } }
FieldValueTool { public static void applyDefaultIfEmpty(final Consumer<String> fieldSetter, final Supplier<String> fieldGetter, final Supplier<Object> defaultGetter) { String text = fieldGetter.get(); if (text.isEmpty()) { fieldSetter.accept(defaultGetter.get().toString()); } } private  FieldValueTool(); }
FieldValueTool { public static void applyDefaultIfEmpty(final Consumer<String> fieldSetter, final Supplier<String> fieldGetter, final Supplier<Object> defaultGetter) { String text = fieldGetter.get(); if (text.isEmpty()) { fieldSetter.accept(defaultGetter.get().toString()); } } 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 void applyDefaultIfEmpty(final Consumer<String> fieldSetter, final Supplier<String> fieldGetter, final Supplier<Object> defaultGetter) { String text = fieldGetter.get(); if (text.isEmpty()) { fieldSetter.accept(defaultGetter.get().toString()); } } 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);  }