ModelFieldUtil { public static ModelField[] getAvailableFieldCompletions(final ModelField[] fieldCompletions, final ActionFieldList afl) { if (fieldCompletions == null || fieldCompletions.length == 0) { return fieldCompletions; } if (afl == null || afl.getFieldValues().length == 0) { return fieldCompletions; } final List<ModelField> availableModelFields = new ArrayList<>(); availableModelFields.addAll(Arrays.asList(fieldCompletions)); for (ActionFieldValue afv : afl.getFieldValues()) { final List<ModelField> usedModelFields = availableModelFields.stream().filter(m -> m.getName().equals(afv.getField())).collect(Collectors.toList()); availableModelFields.removeAll(usedModelFields); } return availableModelFields.toArray(new ModelField[availableModelFields.size()]); }  static ModelField[] getAvailableFieldCompletions(final ModelField[] fieldCompletions,
                                                            final ActionFieldList afl); static ModelField modelField(final String fieldName,
                                        final String fieldDataType);  }
@Test public void nullModelFields() { assertNull(ModelFieldUtil.getAvailableFieldCompletions(null, null)); }
@Test public void emptyModelFields() { assertEquals(0, ModelFieldUtil.getAvailableFieldCompletions(new ModelField[]{}, null).length); }
@Test public void nullActionFieldList() { final ModelField[] result = ModelFieldUtil.getAvailableFieldCompletions(new ModelField[]{field1}, null); assertEquals(1, result.length); assertEquals(field1, result[0]); }
@Test public void emptyActionFieldList() { final ModelField[] result = ModelFieldUtil.getAvailableFieldCompletions(new ModelField[]{field1}, new ActionInsertFact()); assertEquals(1, result.length); assertEquals(field1, result[0]); }
@Test public void filtering() { when(field1.getName()).thenReturn("field1"); when(field2.getName()).thenReturn("field2"); final ActionFieldList afl = new ActionInsertFact(); final ActionFieldValue afv = new ActionFieldValue(); afv.setField("field1"); afl.addFieldValue(afv); final ModelField[] result = ModelFieldUtil.getAvailableFieldCompletions(new ModelField[]{field1, field2}, afl); assertEquals(1, result.length); assertEquals(field2, result[0]); }