GridDDMFormFieldValueAccessor implements DDMFormFieldValueAccessor<JSONObject> { @Override public boolean isEmpty(DDMFormFieldValue ddmFormFieldValue, Locale locale) { JSONObject jsonObject = getValue(ddmFormFieldValue, locale); Set<String> keys = getUniqueKeys(jsonObject); Set<String> rowValues = getDDMFormFieldRowValues( ddmFormFieldValue.getDDMFormField()); Stream<String> stream = rowValues.stream(); return stream.anyMatch(rowValue -> !keys.contains(rowValue)); }  @Override IntFunction<JSONObject[]> getArrayGeneratorIntFunction(); @Override JSONObject getValue(
		DDMFormFieldValue ddmFormFieldValue, Locale locale); @Override JSONObject getValueForEvaluation(
		DDMFormFieldValue ddmFormFieldValue, Locale locale); @Override boolean isEmpty(DDMFormFieldValue ddmFormFieldValue, Locale locale);  }
@Test public void testEmpty() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createDDMFormField( "Grid", "Grid", "grid", "string", false, false, true); DDMFormFieldOptions ddmFormFieldOptions = new DDMFormFieldOptions(); ddmFormFieldOptions.addOptionLabel("row1", LocaleUtil.US, "Row 1"); ddmFormFieldOptions.addOptionLabel("row2", LocaleUtil.US, "Row 2"); ddmFormField.setProperty("rows", ddmFormFieldOptions); ddmForm.addDDMFormField(ddmFormField); DDMFormValues ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues( ddmForm); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createDDMFormFieldValue( "Grid", new UnlocalizedValue("{\"row1\":\"column1\"}")); ddmFormFieldValue.setDDMFormValues(ddmFormValues); Assert.assertTrue( _gridDDMFormFieldValueAccessor.isEmpty( ddmFormFieldValue, LocaleUtil.US)); }
@Test public void testNotEmpty() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createDDMFormField( "Grid", "Grid", "grid", "string", false, false, true); DDMFormFieldOptions ddmFormFieldOptions = new DDMFormFieldOptions(); ddmFormFieldOptions.addOptionLabel("row1", LocaleUtil.US, "Row 1"); ddmFormFieldOptions.addOptionLabel("row2", LocaleUtil.US, "Row 2"); ddmFormField.setProperty("rows", ddmFormFieldOptions); ddmForm.addDDMFormField(ddmFormField); DDMFormValues ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues( ddmForm); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createDDMFormFieldValue( "Grid", new UnlocalizedValue( "{\"row1\":\"column1\",\"row2\":\"column1\"}")); ddmFormFieldValue.setDDMFormValues(ddmFormValues); Assert.assertFalse( _gridDDMFormFieldValueAccessor.isEmpty( ddmFormFieldValue, LocaleUtil.US)); }