@@ -174,14 +174,24 @@ public void repair(E object, ChoiceValue<BooleanChoiceDefinition> deleteifinvali
174
174
// gets previous children
175
175
F [] previouschildren = this .casteddefinition .getChildren (object .getId ());
176
176
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
+
178
182
// get MultiDimensionHelper
179
183
MultidimensionchildHelper <F , E > multidimensionalchildhelper = this .casteddefinition .getHelper ();
180
184
multidimensionalchildhelper .setContext (object );
181
185
for (int i = 0 ; i < previouschildren .length ; i ++) {
182
186
F thischild = previouschildren [i ];
183
187
String key = multidimensionalchildhelper .generateKeyForObject (thischild );
188
+ if (childrenbykey .containsKey (key )) {
189
+ duplicatechildren .add (thischild );
190
+
191
+ }
192
+ else {
184
193
childrenbykey .put (key , thischild );
194
+ }
185
195
}
186
196
187
197
// check missing mandatory
@@ -202,6 +212,8 @@ public void repair(E object, ChoiceValue<BooleanChoiceDefinition> deleteifinvali
202
212
compulsorychildren .put (key , thisobject );
203
213
}
204
214
215
+
216
+
205
217
// detects optionals and invalids
206
218
207
219
ArrayList <F > optionalsandinvalids = new ArrayList <F >();
@@ -250,6 +262,19 @@ public void repair(E object, ChoiceValue<BooleanChoiceDefinition> deleteifinvali
250
262
unconsolidatedinvalids .add (invalid );
251
263
}
252
264
}
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
+
253
278
// Complete optionals with missing primary values
254
279
255
280
for (int i = 0 ; i < optionals .size (); i ++) {
0 commit comments