IsEmptyFunction implements DDMExpressionFunction.Function1<Object, Boolean> { @Override public Boolean apply(Object parameter) { if (parameter == null) { return true; } if (isArray(parameter)) { Object[] values = (Object[])parameter; return Stream.of( values ).allMatch( Validator::isNull ); } if (parameter instanceof JSONArray) { JSONArray jsonArray = (JSONArray)parameter; return jsonArray.length() == 0; } if (parameter instanceof JSONObject) { JSONObject jsonObject = (JSONObject)parameter; return jsonObject.length() == 0; } return Validator.isNull(parameter); }  @Override Boolean apply(Object parameter); @Override String getName(); static final String NAME; }
@Test public void testArray() { IsEmptyFunction isEmptyFunction = new IsEmptyFunction(); Boolean result = isEmptyFunction.apply( new String[] {" ", "not empty "}); Assert.assertFalse(result); }
@Test public void testEmptyParameter() { IsEmptyFunction isEmptyFunction = new IsEmptyFunction(); Boolean result = isEmptyFunction.apply(" "); Assert.assertTrue(result); }
@Test public void testNullParameter() { IsEmptyFunction isEmptyFunction = new IsEmptyFunction(); Boolean result = isEmptyFunction.apply(null); Assert.assertTrue(result); }