@@ -174,14 +174,24 @@ public void repair(E object, ChoiceValue<BooleanChoiceDefinition> deleteifinvali
174174 // gets previous children
175175 F [] previouschildren = this .casteddefinition .getChildren (object .getId ());
176176 HashMap <String , F > childrenbykey = new HashMap <String , F >();
177-
177+
178+ // Creates a list of duplicates to be removed, newest children are stored here to be removed later
179+
180+ ArrayList <F > duplicatechildren = new ArrayList <F >();
181+
178182 // get MultiDimensionHelper
179183 MultidimensionchildHelper <F , E > multidimensionalchildhelper = this .casteddefinition .getHelper ();
180184 multidimensionalchildhelper .setContext (object );
181185 for (int i = 0 ; i < previouschildren .length ; i ++) {
182186 F thischild = previouschildren [i ];
183187 String key = multidimensionalchildhelper .generateKeyForObject (thischild );
188+ if (childrenbykey .containsKey (key )) {
189+ duplicatechildren .add (thischild );
190+
191+ }
192+ else {
184193 childrenbykey .put (key , thischild );
194+ }
185195 }
186196
187197 // check missing mandatory
@@ -202,6 +212,8 @@ public void repair(E object, ChoiceValue<BooleanChoiceDefinition> deleteifinvali
202212 compulsorychildren .put (key , thisobject );
203213 }
204214
215+
216+
205217 // detects optionals and invalids
206218
207219 ArrayList <F > optionalsandinvalids = new ArrayList <F >();
@@ -250,6 +262,19 @@ public void repair(E object, ChoiceValue<BooleanChoiceDefinition> deleteifinvali
250262 unconsolidatedinvalids .add (invalid );
251263 }
252264 }
265+ // process duplicates, consolidates value
266+
267+ for (int i =0 ;i <duplicatechildren .size ();i ++) {
268+ F thisduplicate = duplicatechildren .get (i );
269+ String keyforduplicate = multidimensionalchildhelper .generateKeyForObject (thisduplicate );
270+ if (childrenbykey .get (keyforduplicate ) != null ) {
271+ F childtoconsolidateinto = childrenbykey .get (keyforduplicate );
272+ multidimensionalchildhelper .getConsolidator ().accept (childtoconsolidateinto , thisduplicate );
273+ allobjectstodelete .add (thisduplicate );
274+ logger .finer (" -> found object to consolidate the duplicate into " );
275+ }
276+ }
277+
253278 // Complete optionals with missing primary values
254279
255280 for (int i = 0 ; i < optionals .size (); i ++) {
0 commit comments