@@ -49,21 +49,20 @@ public abstract class MultichildValueHelper<
4949 private BiConsumer <E , F > setter ;
5050 private Function <E , F > getter ;
5151
52- private TriConsumer <Cell ,String [], F > cellfiller ;
52+ private TriConsumer <Cell , String [], F > cellfiller ;
5353 private String [] restrictions ;
54- private TriFunction <Object , ChoiceValue <ApplocaleChoiceDefinition >,String [],F > payloadparser ;
54+ private TriFunction <Object , ChoiceValue <ApplocaleChoiceDefinition >, String [], F > payloadparser ;
5555 private String fieldname ;
56- private BiFunction <F ,F ,F > valueconsolidator ;
57-
58-
56+ private BiFunction <F , F , F > valueconsolidator ;
57+
5958 private Function <F , String > printer ;
6059
6160 public MultichildValueHelper (
6261 String fieldname ,
6362 BiConsumer <E , F > setter ,
6463 Function <E , F > getter ,
65- TriConsumer <Cell ,String [], F > cellfiller ,
66- TriFunction <Object , ChoiceValue <ApplocaleChoiceDefinition >,String [], F > payloadparser ,
64+ TriConsumer <Cell , String [], F > cellfiller ,
65+ TriFunction <Object , ChoiceValue <ApplocaleChoiceDefinition >, String [], F > payloadparser ,
6766 Function <F , String > printer ) {
6867 this .fieldname = fieldname ;
6968 this .setter = setter ;
@@ -72,34 +71,33 @@ public MultichildValueHelper(
7271 this .payloadparser = payloadparser ;
7372 this .printer = printer ;
7473 this .restrictions = null ;
75- this .valueconsolidator = null ;
74+ this .valueconsolidator = null ;
7675 }
77-
76+
7877 public MultichildValueHelper (
7978 String fieldname ,
8079 BiConsumer <E , F > setter ,
8180 Function <E , F > getter ,
82- TriConsumer <Cell ,String [], F > cellfiller ,
83- TriFunction <Object , ChoiceValue <ApplocaleChoiceDefinition >,String [], F > payloadparser ,
81+ TriConsumer <Cell , String [], F > cellfiller ,
82+ TriFunction <Object , ChoiceValue <ApplocaleChoiceDefinition >, String [], F > payloadparser ,
8483 Function <F , String > printer ,
85- BiFunction <F ,F , F > valueconsolidator ) {
84+ BiFunction <F , F , F > valueconsolidator ) {
8685 this .fieldname = fieldname ;
8786 this .setter = setter ;
8887 this .getter = getter ;
8988 this .cellfiller = cellfiller ;
9089 this .payloadparser = payloadparser ;
9190 this .printer = printer ;
9291 this .restrictions = null ;
93- this .valueconsolidator = valueconsolidator ;
92+ this .valueconsolidator = valueconsolidator ;
9493 }
9594
96-
9795 public MultichildValueHelper (
9896 String fieldname ,
9997 BiConsumer <E , F > setter ,
10098 Function <E , F > getter ,
101- TriConsumer <Cell ,String [], F > cellfiller ,
102- TriFunction <Object , ChoiceValue <ApplocaleChoiceDefinition >,String [], F > payloadparser ,
99+ TriConsumer <Cell , String [], F > cellfiller ,
100+ TriFunction <Object , ChoiceValue <ApplocaleChoiceDefinition >, String [], F > payloadparser ,
103101 Function <F , String > printer ,
104102 String [] restrictions ) {
105103 this .fieldname = fieldname ;
@@ -109,18 +107,18 @@ public MultichildValueHelper(
109107 this .payloadparser = payloadparser ;
110108 this .printer = printer ;
111109 this .restrictions = restrictions ;
112- this .valueconsolidator = null ;
110+ this .valueconsolidator = null ;
113111 }
114112
115113 public MultichildValueHelper (
116114 String fieldname ,
117115 BiConsumer <E , F > setter ,
118116 Function <E , F > getter ,
119- TriConsumer <Cell ,String [], F > cellfiller ,
120- TriFunction <Object , ChoiceValue <ApplocaleChoiceDefinition >,String [], F > payloadparser ,
117+ TriConsumer <Cell , String [], F > cellfiller ,
118+ TriFunction <Object , ChoiceValue <ApplocaleChoiceDefinition >, String [], F > payloadparser ,
121119 Function <F , String > printer ,
122120 String [] restrictions ,
123- BiFunction <F ,F , F > valueconsolidator ) {
121+ BiFunction <F , F , F > valueconsolidator ) {
124122 this .fieldname = fieldname ;
125123 this .setter = setter ;
126124 this .getter = getter ;
@@ -130,9 +128,28 @@ public MultichildValueHelper(
130128 this .restrictions = restrictions ;
131129 this .valueconsolidator = valueconsolidator ;
132130 }
133-
134-
135-
131+
132+ /**
133+ * this method is only relevant to be implemented for a main value helper. It
134+ * should return true when the column should be consolidated for totals
135+ *
136+ * @param value value of the object
137+ * @return true if it should be consolidated into the total, false if it should
138+ * be discarded
139+ */
140+
141+ public abstract boolean filterForPayloadTotal (F value );
142+
143+ /**
144+ * This method will determine if the object is a candidate for total column
145+ *
146+ * @param object the object with the MultiDimensionChild property
147+ * @return true if the payload should be consolidated, or false else
148+ */
149+ public boolean filterForPayloadTotalFromObject (E object ) {
150+ return filterForPayloadTotal (this .get (object ));
151+ }
152+
136153 public String getFieldName () {
137154 return this .fieldname ;
138155 }
@@ -160,18 +177,18 @@ public void set(E object, F payload) {
160177 * @param cell
161178 * @param object
162179 */
163- public void fillCell (Cell cell , E object ,String [] extraattributes ) {
164- this .cellfiller .apply (cell ,extraattributes , this .getter .apply (object ));
180+ public void fillCell (Cell cell , E object , String [] extraattributes ) {
181+ this .cellfiller .apply (cell , extraattributes , this .getter .apply (object ));
165182 }
166183
167184 /**
168185 * @param cell
169186 * @param value
170187 */
171- public void fillCellWithValue (Cell cell ,F value ,String [] extraattributes ) {
172- this .cellfiller .apply (cell ,extraattributes , value );
188+ public void fillCellWithValue (Cell cell , F value , String [] extraattributes ) {
189+ this .cellfiller .apply (cell , extraattributes , value );
173190 }
174-
191+
175192 /**
176193 * gets the payload of the field on the child object
177194 *
@@ -235,7 +252,7 @@ public String getAndPrint(E object) {
235252 * discarded
236253 */
237254 public boolean replaceWithDefaultValue (E object ) {
238- logger .finer (" ------------------ Replace With Default Value audit " + fieldname + " --------------------" );
255+ logger .finer (" ------------------ Replace With Default Value audit " + fieldname + " --------------------" );
239256 if (allowothervalues ()) {
240257 logger .finer ("Allow other values" );
241258 return true ;
@@ -244,40 +261,44 @@ public boolean replaceWithDefaultValue(E object) {
244261 logger .finer ("Allow user values" );
245262 return true ;
246263 }
247-
264+
248265 F [] minimumvalues = this .getMandatoryValues ();
249266 if (minimumvalues != null )
250267 for (int i = 0 ; i < minimumvalues .length ; i ++) {
251- logger .finest (" --> compare " + minimumvalues [i ]+ " and " + get (object ));
268+ logger .finest (" --> compare " + minimumvalues [i ] + " and " + get (object ));
252269 if (StandardUtil .compareIncludesNull (minimumvalues [i ], get (object ))) {
253270 logger .finest (" Match" );
254271 return true ;
255272 }
256-
273+
257274 }
258-
275+
259276 F [] maximumvalues = getOptionalValues ();
260277 if (maximumvalues != null )
261278 for (int i = 0 ; i < maximumvalues .length ; i ++) {
262- logger .finest (" --> compare " + maximumvalues [i ]+ " and " + get (object ));
279+ logger .finest (" --> compare " + maximumvalues [i ] + " and " + get (object ));
263280 if (StandardUtil .compareIncludesNull (maximumvalues [i ], get (object ))) {
264281 logger .finest (" Match" );
265282 return true ;
266283 }
267-
284+
268285 }
269286 F alternative = getDefaultValueForOtherData ();
270287 if (alternative != null ) {
271- logger .finer (" ---> Found alternative " + alternative );
288+ logger .finer (" ---> Found alternative " + alternative );
272289 set (object , alternative );
273290 return true ;
274291 }
275292 logger .finer ("No match found" );
276293 return false ;
277294 }
278295
279- public boolean LoadIfDifferent (E object , Object value , ChoiceValue <ApplocaleChoiceDefinition > applocale ,String [] extraattributes ) {
280- F newvalue = payloadparser .apply (value , applocale ,extraattributes );
296+ public boolean LoadIfDifferent (
297+ E object ,
298+ Object value ,
299+ ChoiceValue <ApplocaleChoiceDefinition > applocale ,
300+ String [] extraattributes ) {
301+ F newvalue = payloadparser .apply (value , applocale , extraattributes );
281302 F oldvalue = getter .apply (object );
282303 if (StandardUtil .compareIncludesNull (newvalue , oldvalue )) {
283304 return false ;
@@ -317,7 +338,8 @@ public SecondValueFlatFileLoader(
317338 public SecondValueFlatFileLoader (
318339 HasmultidimensionalchildFlatFileLoaderHelper <G , E > helper ,
319340 ChoiceValue <ApplocaleChoiceDefinition > applocale ,
320- int index ,String [] extraattributes ) {
341+ int index ,
342+ String [] extraattributes ) {
321343 this .mainsecondary = false ;
322344 this .helper = helper ;
323345 this .index = index ;
@@ -333,8 +355,8 @@ public String[] getValueRestriction() {
333355 @ Override
334356 public boolean load (G object , Object value , PostUpdateProcessingStore <G > postupdateprocessingstore ) {
335357 logger .warning ("Adding value in index " + index + " value = " + value .toString ());
336- helper .setSecondaryValueForLoading (index ,
337- MultichildValueHelper . this . print (MultichildValueHelper .this .payloadparser .apply (value , applocale ,extraattributes )));
358+ helper .setSecondaryValueForLoading (index , MultichildValueHelper . this
359+ . print (MultichildValueHelper .this .payloadparser .apply (value , applocale , extraattributes )));
338360
339361 // returns false as no change of value is done
340362 return false ;
@@ -367,25 +389,29 @@ public boolean isComplexExtractor() {
367389 }
368390
369391 public class MainValueTotalFlatFileLoader
370- extends FlatFileLoaderColumn <G > {
392+ extends
393+ FlatFileLoaderColumn <G > {
371394
372395 private HasmultidimensionalchildFlatFileLoaderHelper <G , E > helper ;
373396 @ SuppressWarnings ("unused" )
374397 private ChoiceValue <ApplocaleChoiceDefinition > applocale ;
375398 @ SuppressWarnings ("unused" )
376399 private MultichildValueHelper <E , F , G > payloadhelper ;
377400 private String [] extraattributes ;
401+ private MultichildValueHelper <E , ?, G > mainvaluehelper ;
378402
379403 @ SuppressWarnings ("unchecked" )
380404 public MainValueTotalFlatFileLoader (
381405 HasmultidimensionalchildFlatFileLoaderHelper <G , E > helper ,
382406 ChoiceValue <ApplocaleChoiceDefinition > applocale ,
383- MultichildValueHelper <E , ?, G > payloadhelper ,String [] extraattributes ) {
407+ MultichildValueHelper <E , ?, G > payloadhelper ,
408+ String [] extraattributes ) {
384409
385410 this .helper = helper ;
386411 this .applocale = applocale ;
387412 this .payloadhelper = (MultichildValueHelper <E , F , G >) payloadhelper ;
388413 this .extraattributes = extraattributes ;
414+ mainvaluehelper = helper .getMainValueHelper ();
389415 }
390416
391417 @ Override
@@ -400,23 +426,27 @@ public boolean load(G object, Object value, PostUpdateProcessingStore<G> postupd
400426
401427 @ Override
402428 protected boolean putContentInCell (G currentobject , Cell cell , String context ) {
403- logger .finer ("Processing total column for object " + currentobject .dropIdToString ());
429+ logger .finer ("Processing total column for object " + currentobject .dropIdToString ());
404430 ArrayList <E > children = helper .getChildrenForLine (context );
405431 F total = null ;
406- if (valueconsolidator ==null ) throw new RuntimeException ("No value consolidator for " +this .getClass ()+" and " +MultichildValueHelper .this .getClass ());
407- for (int i =0 ;i <children .size ();i ++) {
408- F value = getter .apply (children .get (i ));
409- logger .finer (" > " +value );
410-
411- total = valueconsolidator .apply (total ,value );
432+ if (valueconsolidator == null )
433+ throw new RuntimeException ("No value consolidator for " + this .getClass () + " and "
434+ + MultichildValueHelper .this .getClass ());
435+ for (int i = 0 ; i < children .size (); i ++) {
436+ boolean valid = mainvaluehelper .filterForPayloadTotalFromObject (children .get (i ));
437+ if (valid ) {
438+ F value = getter .apply (children .get (i ));
439+ logger .finer (" > " + value );
440+ total = valueconsolidator .apply (total , value );
441+ }
412442 }
413- logger .finer (" ----> total " + total );
414- payloadhelper .fillCellWithValue (cell , total ,extraattributes );
415-
443+ logger .finer (" ----> total " + total );
444+ payloadhelper .fillCellWithValue (cell , total , extraattributes );
445+
416446 return true ;
417447 }
418448 }
419-
449+
420450 public class MainValueFlatFileLoader
421451 extends
422452 FlatFileLoaderColumn <G > {
@@ -431,8 +461,9 @@ public MainValueFlatFileLoader(
431461 HasmultidimensionalchildFlatFileLoaderHelper <G , E > helper ,
432462 ChoiceValue <ApplocaleChoiceDefinition > applocale ,
433463 String unparsedpayload ,
434- MultichildValueHelper <E , ?, G > payloadhelper ,String [] extraattributes ) {
435- this .mainvalue = MultichildValueHelper .this .payloadparser .apply (unparsedpayload , applocale ,null );
464+ MultichildValueHelper <E , ?, G > payloadhelper ,
465+ String [] extraattributes ) {
466+ this .mainvalue = MultichildValueHelper .this .payloadparser .apply (unparsedpayload , applocale , null );
436467 this .helper = helper ;
437468 this .applocale = applocale ;
438469 this .payloadhelper = payloadhelper ;
@@ -454,22 +485,23 @@ public boolean load(G object, Object value, PostUpdateProcessingStore<G> postupd
454485 throw new RuntimeException ("Did not find existing child for key, debug = " + helper
455486 .getDebugForLineAndColumnKey (helpercontextkey , MultichildValueHelper .this .print (mainvalue )));
456487 }
457- return this .payloadhelper .LoadIfDifferent (relevantchild , value , applocale ,extraattributes );
488+ return this .payloadhelper .LoadIfDifferent (relevantchild , value , applocale , extraattributes );
458489
459490 }
460491
461492 @ Override
462493 protected boolean putContentInCell (G currentobject , Cell cell , String context ) {
463494 E child = helper .getChildForLineAndColumnKey (context , MultichildValueHelper .this .print (mainvalue ));
464495 if (child == null ) {
465- logger .warning (
466- "Did not find child for context = " + context + " for object " + currentobject .dropToString ()
467- + " for mainvalue = " + MultichildValueHelper .this .printer .apply (this .mainvalue )+", debug = " +helper .getDebugForLineAndColumnKey (context , MultichildValueHelper .this .print (mainvalue )));
496+ logger .warning ("Did not find child for context = " + context + " for object "
497+ + currentobject .dropToString () + " for mainvalue = "
498+ + MultichildValueHelper .this .printer .apply (this .mainvalue ) + ", debug = "
499+ + helper .getDebugForLineAndColumnKey (context , MultichildValueHelper .this .print (mainvalue )));
468500
469501 return false ;
470502 }
471503 MultichildValueHelper <E , ?, G > payloadhelper = helper .getPayloadHelper ();
472- payloadhelper .fillCell (cell , child ,extraattributes );
504+ payloadhelper .fillCell (cell , child , extraattributes );
473505
474506 return true ;
475507 }
0 commit comments