/** * If the provided nullValue is null, empty, or just whitespace then the returned value * will be null. Otherwise, this function will look in the provided {@link BindingContext} * to find a constant with the name of the nullValue string and return that. If there is * no constant then the nullValue string itself will be returned. * @see JComboBoxWiringHarness * @see BoundSelection.Wiring */ public static Object getNullValue(BindingContext context, String nullValue) { final String finalNullValue; if (isNullOrBlank(nullValue)) { finalNullValue = null; } else { Object constant = context.getBindableConstant(nullValue); if (constant != null) { finalNullValue = constant.toString(); } else { finalNullValue = nullValue; } } return finalNullValue; }
public Collection<Binding> wire(BindingContext context) { List<Field> actions = context.getAnnotatedFields(OnFocusChange.class); for (Field field : actions) { OnFocusChange focusChange = field.getAnnotation(OnFocusChange.class); String lost = normalizeString(focusChange.lost()); String gained = normalizeString(focusChange.gained()); if (Bound.Utilities.isNullOrBlank(lost) && Bound.Utilities.isNullOrBlank(gained)) { throw new BindingException("either lost or gained must be specified on @OnFocusChange on " + field.getName()); } try { wire(lost, gained, field, context); } catch (Exception e) { throw new BindingException("could not wire up @OnFocusChange " + field.getName(), e); } } return ImmutableList.of(); }
private static String normalizeString(String string) { if (Bound.Utilities.isNullOrBlank(string)) { return null; } return string; }
public void testIsNullOrBlank() { assertTrue(Bound.Utilities.isNullOrBlank(null)); assertTrue(Bound.Utilities.isNullOrBlank("")); assertTrue(Bound.Utilities.isNullOrBlank(" ")); assertFalse(Bound.Utilities.isNullOrBlank("a")); assertFalse(Bound.Utilities.isNullOrBlank(" a b c ")); }