EntityUtil { public static boolean areFieldModelsEqualByContent(FieldModel leftFieldModel, FieldModel rightFieldModel) { if(!Objects.equals(leftFieldModel.getName(), rightFieldModel.getName())){ return false; } if(!leftFieldModel.getClass().equals(rightFieldModel.getClass())) { return false; } if(leftFieldModel instanceof ReferenceFieldModel && rightFieldModel instanceof ReferenceFieldModel) { EntityModel refLeftEntityModel = (EntityModel) leftFieldModel.getValue(); EntityModel refRightEntityModel = (EntityModel) rightFieldModel.getValue(); return areEqualByContent(refLeftEntityModel, refRightEntityModel); } if(leftFieldModel instanceof MultiReferenceFieldModel && rightFieldModel instanceof MultiReferenceFieldModel) { Collection<EntityModel> refLeftEntityModel = ((MultiReferenceFieldModel)leftFieldModel).getValue(); Collection<EntityModel> refRightEntityModel = ((MultiReferenceFieldModel)rightFieldModel).getValue(); return containsSameEntities(refLeftEntityModel, refRightEntityModel, EntityUtil::areEqualByContent); } return Objects.equals(leftFieldModel.getValue(), rightFieldModel.getValue()); }  static boolean areEqualByIdAndType(EntityModel leftEntityModel, EntityModel rightEntityModel); static boolean areEqualByContent(EntityModel leftEntityModel, EntityModel rightEntityModel); static boolean areFieldModelsEqualByContent(FieldModel leftFieldModel, FieldModel rightFieldModel); static boolean containsEntityModel(Collection<EntityModel> collection, EntityModel entityModel); static boolean containsEntityModel(Collection<EntityModel> collection, EntityModel entityModel, EntityEquator entityEquator); static boolean containsAllEntityModels(Collection<EntityModel> baseCollection, Collection<EntityModel> sourceCollection, EntityEquator entityEquator); static boolean containsSameEntities(Collection<EntityModel> leftCollection, Collection<EntityModel> rightCollection, EntityEquator entityEquator); static boolean removeEntityModel(Collection<EntityModel> collection, EntityModel entityModel); static boolean removeEntityModel(Collection<EntityModel> collection, EntityModel entityModel, EntityEquator entityEquator);  }
@Test public void testLongFieldModelEquals() { fieldModelOne = new LongFieldModel("id", 1L); fieldModelTwo = new LongFieldModel("id", 1L); assertTrue(EntityUtil.areFieldModelsEqualByContent(fieldModelOne, fieldModelTwo)); }
@Test public void testBooleanFieldModelEquals() { fieldModelOne = new BooleanFieldModel("field", true); fieldModelTwo = new BooleanFieldModel("field", false); assertFalse(EntityUtil.areFieldModelsEqualByContent(fieldModelOne, fieldModelTwo)); }
@Test public void testStringFieldModelEquals() { fieldModelOne = new StringFieldModel("field", "string"); fieldModelTwo = new StringFieldModel("field", "string"); assertTrue(EntityUtil.areFieldModelsEqualByContent(fieldModelOne, fieldModelTwo)); }
@Test public void testDifferentFieldModelEquals() { fieldModelOne = new StringFieldModel("fieldOne", "string"); fieldModelTwo = new StringFieldModel("fieldTwo", "string"); assertFalse(EntityUtil.areFieldModelsEqualByContent(fieldModelOne, fieldModelTwo)); }
@Test public void testLongStringFieldModelEquals() { fieldModelOne = new LongFieldModel("id", 1L); fieldModelTwo = new StringFieldModel("id", "1"); assertFalse(EntityUtil.areFieldModelsEqualByContent(fieldModelOne, fieldModelTwo)); }
@Test public void testFloatLongFieldModelEquals() { fieldModelOne = new FloatFieldModel("id", 1.0F); fieldModelTwo = new LongFieldModel("id", 1L); assertFalse(EntityUtil.areFieldModelsEqualByContent(fieldModelOne, fieldModelTwo)); }
@Test public void testBooleanStringFieldModelEquals() { fieldModelOne = new BooleanFieldModel("field", true); fieldModelTwo = new StringFieldModel("field", "true"); assertFalse(EntityUtil.areFieldModelsEqualByContent(fieldModelOne, fieldModelTwo)); }
@Test public void testDateFieldModelEquals() { ZonedDateTime dateTime = ZonedDateTime.now(); fieldModelOne = new DateFieldModel("field", dateTime); fieldModelTwo = new DateFieldModel("field", dateTime); assertTrue(EntityUtil.areFieldModelsEqualByContent(fieldModelOne, fieldModelTwo)); fieldModelOne = new DateFieldModel("field", dateTime); fieldModelTwo = new DateFieldModel("field", dateTime.plusHours(1L)); assertFalse(EntityUtil.areFieldModelsEqualByContent(fieldModelOne, fieldModelTwo)); }