/** * 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 void testConstants() { BindingContext context = new BindingContext(this); assertEquals("string1", context.getBindableConstant("STRING_1")); assertEquals(Boolean.TRUE, context.getBindableConstant("BOOLEAN")); assertEquals("privateString", context.getBindableConstant("PRIVATE_STRING")); assertEquals("#0", context.getBindableConstant("FUNCTION_STRING")); assertEquals(null, context.getBindableConstant("NOT_FOUND")); }