View Javadoc
1   /*
2    * MoneyWise: Finance Application
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets;
18  
19  import io.github.tonywasher.joceanus.oceanus.date.OceanusDate;
20  import io.github.tonywasher.joceanus.oceanus.date.OceanusDateRange;
21  import io.github.tonywasher.joceanus.oceanus.decimal.OceanusDecimal;
22  import io.github.tonywasher.joceanus.oceanus.decimal.OceanusMoney;
23  import io.github.tonywasher.joceanus.oceanus.format.OceanusDataFormatter;
24  import io.github.tonywasher.joceanus.metis.data.MetisDataFieldValue;
25  import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataFieldId;
26  import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataList;
27  import io.github.tonywasher.joceanus.metis.field.MetisFieldItem;
28  import io.github.tonywasher.joceanus.metis.field.MetisFieldItem.MetisFieldTableItem;
29  import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
30  import io.github.tonywasher.joceanus.metis.list.MetisListIndexed;
31  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.base.MoneyWiseXAnalysisEvent;
32  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.base.MoneyWiseXAnalysisHistory;
33  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisInterfaces.MoneyWiseXAnalysisBucketRegister;
34  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.values.MoneyWiseXAnalysisPayeeAttr;
35  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.values.MoneyWiseXAnalysisPayeeValues;
36  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseAssetBase;
37  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicDataType;
38  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee;
39  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee.MoneyWisePayeeList;
40  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseCurrency;
41  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWisePayeeClass;
42  import io.github.tonywasher.joceanus.prometheus.views.PrometheusEditSet;
43  
44  import java.util.Currency;
45  import java.util.Iterator;
46  import java.util.List;
47  
48  /**
49   * The Payee Bucket class.
50   */
51  public final class MoneyWiseXAnalysisPayeeBucket
52          implements MetisFieldTableItem, MoneyWiseXAnalysisBucketRegister {
53      /**
54       * Local Report fields.
55       */
56      private static final MetisFieldSet<MoneyWiseXAnalysisPayeeBucket> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseXAnalysisPayeeBucket.class);
57  
58      /*
59       * Declare Fields.
60       */
61      static {
62          FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBucketResource.ANALYSIS_NAME, MoneyWiseXAnalysisPayeeBucket::getAnalysis);
63          FIELD_DEFS.declareLocalField(MoneyWiseBasicDataType.PAYEE, MoneyWiseXAnalysisPayeeBucket::getPayee);
64          FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBucketResource.BUCKET_BASEVALUES, MoneyWiseXAnalysisPayeeBucket::getBaseValues);
65          FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBucketResource.BUCKET_HISTORY, MoneyWiseXAnalysisPayeeBucket::getHistoryMap);
66          FIELD_DEFS.declareLocalFieldsForEnum(MoneyWiseXAnalysisPayeeAttr.class, MoneyWiseXAnalysisPayeeBucket::getAttributeValue);
67      }
68  
69      /**
70       * Totals bucket name.
71       */
72      private static final MetisDataFieldId NAME_TOTALS = MoneyWiseXAnalysisBucketResource.ANALYSIS_TOTALS;
73  
74      /**
75       * The analysis.
76       */
77      private final MoneyWiseXAnalysis theAnalysis;
78  
79      /**
80       * The payee.
81       */
82      private final MoneyWisePayee thePayee;
83  
84      /**
85       * Values.
86       */
87      private final MoneyWiseXAnalysisPayeeValues theValues;
88  
89      /**
90       * The base values.
91       */
92      private final MoneyWiseXAnalysisPayeeValues theBaseValues;
93  
94      /**
95       * History Map.
96       */
97      private final MoneyWiseXAnalysisHistory<MoneyWiseXAnalysisPayeeValues, MoneyWiseXAnalysisPayeeAttr> theHistory;
98  
99      /**
100      * Constructor.
101      *
102      * @param pAnalysis the analysis
103      * @param pPayee    the payee
104      */
105     private MoneyWiseXAnalysisPayeeBucket(final MoneyWiseXAnalysis pAnalysis,
106                                           final MoneyWisePayee pPayee) {
107         /* Store the details */
108         thePayee = pPayee;
109         theAnalysis = pAnalysis;
110 
111         /* Create the history map */
112         final MoneyWiseCurrency myDefault = theAnalysis.getCurrency();
113         final Currency myCurrency = myDefault == null
114                 ? MoneyWiseXAnalysisAccountBucket.DEFAULT_CURRENCY
115                 : myDefault.getCurrency();
116         final MoneyWiseXAnalysisPayeeValues myValues = new MoneyWiseXAnalysisPayeeValues(myCurrency);
117         theHistory = new MoneyWiseXAnalysisHistory<>(myValues);
118 
119         /* Access the key value maps */
120         theValues = theHistory.getValues();
121         theBaseValues = theHistory.getBaseValues();
122     }
123 
124     /**
125      * Constructor.
126      *
127      * @param pAnalysis the analysis
128      * @param pBase     the underlying bucket
129      * @param pDate     the date for the bucket
130      */
131     private MoneyWiseXAnalysisPayeeBucket(final MoneyWiseXAnalysis pAnalysis,
132                                           final MoneyWiseXAnalysisPayeeBucket pBase,
133                                           final OceanusDate pDate) {
134         /* Copy details from base */
135         thePayee = pBase.getPayee();
136         theAnalysis = pAnalysis;
137 
138         /* Access the relevant history */
139         theHistory = new MoneyWiseXAnalysisHistory<>(pBase.getHistoryMap(), pDate);
140 
141         /* Access the key value maps */
142         theValues = theHistory.getValues();
143         theBaseValues = theHistory.getBaseValues();
144     }
145 
146     /**
147      * Constructor.
148      *
149      * @param pAnalysis the analysis
150      * @param pBase     the underlying bucket
151      * @param pRange    the range for the bucket
152      */
153     private MoneyWiseXAnalysisPayeeBucket(final MoneyWiseXAnalysis pAnalysis,
154                                           final MoneyWiseXAnalysisPayeeBucket pBase,
155                                           final OceanusDateRange pRange) {
156         /* Copy details from base */
157         thePayee = pBase.getPayee();
158         theAnalysis = pAnalysis;
159 
160         /* Access the relevant history */
161         theHistory = new MoneyWiseXAnalysisHistory<>(pBase.getHistoryMap(), pRange);
162 
163         /* Access the key value maps */
164         theValues = theHistory.getValues();
165         theBaseValues = theHistory.getBaseValues();
166     }
167 
168     @Override
169     public MetisFieldSet<MoneyWiseXAnalysisPayeeBucket> getDataFieldSet() {
170         return FIELD_DEFS;
171     }
172 
173     @Override
174     public String formatObject(final OceanusDataFormatter pFormatter) {
175         return toString();
176     }
177 
178     @Override
179     public String toString() {
180         return getName() + " " + theValues;
181     }
182 
183     /**
184      * Obtain the name.
185      *
186      * @return the name
187      */
188     public String getName() {
189         return thePayee == null
190                 ? NAME_TOTALS.getId()
191                 : thePayee.getName();
192     }
193 
194     /**
195      * Obtain the payee.
196      *
197      * @return the payee account
198      */
199     public MoneyWisePayee getPayee() {
200         return thePayee;
201     }
202 
203     @Override
204     public Integer getIndexedId() {
205         return thePayee.getIndexedId();
206     }
207 
208     @Override
209     public Long getBucketId() {
210         return thePayee.getExternalId();
211     }
212 
213     /**
214      * Is this bucket idle?
215      *
216      * @return true/false
217      */
218     public boolean isIdle() {
219         return theHistory.isIdle();
220     }
221 
222     /**
223      * Obtain the analysis.
224      *
225      * @return the analysis
226      */
227     MoneyWiseXAnalysis getAnalysis() {
228         return theAnalysis;
229     }
230 
231     /**
232      * Obtain date range.
233      *
234      * @return the range
235      */
236     public OceanusDateRange getDateRange() {
237         return theAnalysis.getDateRange();
238     }
239 
240     /**
241      * Obtain the value map.
242      *
243      * @return the value map
244      */
245     public MoneyWiseXAnalysisPayeeValues getValues() {
246         return theValues;
247     }
248 
249     /**
250      * Obtain the base value map.
251      *
252      * @return the base value map
253      */
254     public MoneyWiseXAnalysisPayeeValues getBaseValues() {
255         return theBaseValues;
256     }
257 
258     /**
259      * Obtain values for event.
260      *
261      * @param pEvent the event
262      * @return the values (or null)
263      */
264     public MoneyWiseXAnalysisPayeeValues getValuesForEvent(final MoneyWiseXAnalysisEvent pEvent) {
265         /* Obtain values for transaction */
266         return theHistory.getValuesForEvent(pEvent);
267     }
268 
269     /**
270      * Obtain previous values for event.
271      *
272      * @param pEvent the event
273      * @return the values (or null)
274      */
275     public MoneyWiseXAnalysisPayeeValues getPreviousValuesForEvent(final MoneyWiseXAnalysisEvent pEvent) {
276         return theHistory.getPreviousValuesForEvent(pEvent);
277     }
278 
279     /**
280      * Obtain delta for event.
281      *
282      * @param pEvent the event
283      * @param pAttr  the attribute
284      * @return the delta (or null)
285      */
286     public OceanusDecimal getDeltaForEvent(final MoneyWiseXAnalysisEvent pEvent,
287                                            final MoneyWiseXAnalysisPayeeAttr pAttr) {
288         /* Obtain delta for event */
289         return theHistory.getDeltaValue(pEvent, pAttr);
290     }
291 
292     /**
293      * Obtain the history map.
294      *
295      * @return the history map
296      */
297     private MoneyWiseXAnalysisHistory<MoneyWiseXAnalysisPayeeValues, MoneyWiseXAnalysisPayeeAttr> getHistoryMap() {
298         return theHistory;
299     }
300 
301     /**
302      * Set Attribute.
303      *
304      * @param pAttr  the attribute
305      * @param pValue the value of the attribute
306      */
307     void setValue(final MoneyWiseXAnalysisPayeeAttr pAttr,
308                   final Object pValue) {
309         /* Set the value */
310         theValues.setValue(pAttr, pValue);
311     }
312 
313     /**
314      * Get an attribute value.
315      *
316      * @param pAttr the attribute
317      * @return the value to set
318      */
319     private Object getAttributeValue(final MoneyWiseXAnalysisPayeeAttr pAttr) {
320         /* Access value of object */
321         final Object myValue = getValue(pAttr);
322 
323         /* Return the value */
324         return myValue != null
325                 ? myValue
326                 : MetisDataFieldValue.SKIP;
327     }
328 
329     /**
330      * Obtain an attribute value.
331      *
332      * @param pAttr the attribute
333      * @return the value of the attribute or null
334      */
335     private Object getValue(final MoneyWiseXAnalysisPayeeAttr pAttr) {
336         /* Obtain the value */
337         return theValues.getValue(pAttr);
338     }
339 
340     /**
341      * Adjust counter.
342      *
343      * @param pAttr  the attribute
344      * @param pDelta the delta
345      */
346     void adjustCounter(final MoneyWiseXAnalysisPayeeAttr pAttr,
347                        final OceanusMoney pDelta) {
348         OceanusMoney myValue = theValues.getMoneyValue(pAttr);
349         myValue = new OceanusMoney(myValue);
350         myValue.addAmount(pDelta);
351         setValue(pAttr, myValue);
352     }
353 
354     @Override
355     public void registerEvent(final MoneyWiseXAnalysisEvent pEvent) {
356         /* Register the event in the history */
357         theHistory.registerEvent(pEvent, theValues);
358     }
359 
360     /**
361      * Add income value.
362      *
363      * @param pValue the value to add
364      */
365     public void addIncome(final OceanusMoney pValue) {
366         /* Only adjust on non-zero */
367         if (pValue.isNonZero()) {
368             adjustCounter(MoneyWiseXAnalysisPayeeAttr.INCOME, pValue);
369         }
370     }
371 
372     /**
373      * Subtract income value.
374      *
375      * @param pValue the value to subtract
376      */
377     public void subtractIncome(final OceanusMoney pValue) {
378         /* Only adjust on non-zero */
379         if (pValue.isNonZero()) {
380             final OceanusMoney myIncome = new OceanusMoney(pValue);
381             myIncome.negate();
382             adjustCounter(MoneyWiseXAnalysisPayeeAttr.INCOME, myIncome);
383         }
384     }
385 
386     /**
387      * Add expense value.
388      *
389      * @param pValue the value to add
390      */
391     public void addExpense(final OceanusMoney pValue) {
392         /* Only adjust on non-zero */
393         if (pValue.isNonZero()) {
394             adjustCounter(MoneyWiseXAnalysisPayeeAttr.EXPENSE, pValue);
395         }
396     }
397 
398     /**
399      * Subtract expense value.
400      *
401      * @param pValue the value to subtract
402      */
403     public void subtractExpense(final OceanusMoney pValue) {
404         /* Only adjust on non-zero */
405         if (pValue.isNonZero()) {
406             final OceanusMoney myExpense = new OceanusMoney(pValue);
407             myExpense.negate();
408             adjustCounter(MoneyWiseXAnalysisPayeeAttr.EXPENSE, myExpense);
409         }
410     }
411 
412     /**
413      * Add bucket to totals.
414      *
415      * @param pSource the bucket to add
416      */
417     void addValues(final MoneyWiseXAnalysisPayeeBucket pSource) {
418         /* Access source values */
419         final MoneyWiseXAnalysisPayeeValues mySource = pSource.getValues();
420 
421         /* Add income values */
422         OceanusMoney myValue = theValues.getMoneyValue(MoneyWiseXAnalysisPayeeAttr.INCOME);
423         OceanusMoney mySrcValue = mySource.getMoneyValue(MoneyWiseXAnalysisPayeeAttr.INCOME);
424         myValue.addAmount(mySrcValue);
425 
426         /* Add expense values */
427         myValue = theValues.getMoneyValue(MoneyWiseXAnalysisPayeeAttr.EXPENSE);
428         mySrcValue = mySource.getMoneyValue(MoneyWiseXAnalysisPayeeAttr.EXPENSE);
429         myValue.addAmount(mySrcValue);
430     }
431 
432     /**
433      * Calculate delta.
434      */
435     void calculateDelta() {
436         /* Calculate delta for the values */
437         theValues.calculateDelta();
438     }
439 
440     /**
441      * Adjust to base.
442      */
443     void adjustToBase() {
444         /* Adjust to base values */
445         theValues.adjustToBaseValues(theBaseValues);
446         theBaseValues.resetBaseValues();
447     }
448 
449     /**
450      * PayeeBucket list class.
451      */
452     public static final class MoneyWiseXAnalysisPayeeBucketList
453             implements MetisFieldItem, MetisDataList<MoneyWiseXAnalysisPayeeBucket> {
454         /**
455          * Local Report fields.
456          */
457         private static final MetisFieldSet<MoneyWiseXAnalysisPayeeBucketList> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseXAnalysisPayeeBucketList.class);
458 
459         /*
460          * Declare Fields.
461          */
462         static {
463             FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBucketResource.ANALYSIS_NAME, MoneyWiseXAnalysisPayeeBucketList::getAnalysis);
464             FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBucketResource.ANALYSIS_TOTALS, MoneyWiseXAnalysisPayeeBucketList::getTotals);
465         }
466 
467         /**
468          * The analysis.
469          */
470         private final MoneyWiseXAnalysis theAnalysis;
471 
472         /**
473          * The list.
474          */
475         private final MetisListIndexed<MoneyWiseXAnalysisPayeeBucket> theList;
476 
477         /**
478          * The editSet.
479          */
480         private final PrometheusEditSet theEditSet;
481 
482         /**
483          * The totals.
484          */
485         private final MoneyWiseXAnalysisPayeeBucket theTotals;
486 
487         /**
488          * Construct a top-level List.
489          *
490          * @param pAnalysis the analysis
491          */
492         MoneyWiseXAnalysisPayeeBucketList(final MoneyWiseXAnalysis pAnalysis) {
493             /* Initialise class */
494             theAnalysis = pAnalysis;
495             theEditSet = theAnalysis.getEditSet();
496             theTotals = allocateTotalsBucket();
497             theList = new MetisListIndexed<>();
498             theList.setComparator((l, r) -> l.getPayee().compareTo(r.getPayee()));
499         }
500 
501         /**
502          * Construct a dated List.
503          *
504          * @param pAnalysis the analysis
505          * @param pBase     the base list
506          * @param pDate     the Date
507          */
508         MoneyWiseXAnalysisPayeeBucketList(final MoneyWiseXAnalysis pAnalysis,
509                                           final MoneyWiseXAnalysisPayeeBucketList pBase,
510                                           final OceanusDate pDate) {
511             /* Initialise class */
512             this(pAnalysis);
513 
514             /* Loop through the buckets */
515             final Iterator<MoneyWiseXAnalysisPayeeBucket> myIterator = pBase.iterator();
516             while (myIterator.hasNext()) {
517                 final MoneyWiseXAnalysisPayeeBucket myCurr = myIterator.next();
518 
519                 /* Access the bucket for this date */
520                 final MoneyWiseXAnalysisPayeeBucket myBucket = new MoneyWiseXAnalysisPayeeBucket(pAnalysis, myCurr, pDate);
521 
522                 /* If the bucket is non-idle */
523                 if (!myBucket.isIdle()) {
524                     /* Add to the list */
525                     theList.add(myBucket);
526                 }
527             }
528         }
529 
530         /**
531          * Construct a ranged List.
532          *
533          * @param pAnalysis the analysis
534          * @param pBase     the base list
535          * @param pRange    the Date Range
536          */
537         MoneyWiseXAnalysisPayeeBucketList(final MoneyWiseXAnalysis pAnalysis,
538                                           final MoneyWiseXAnalysisPayeeBucketList pBase,
539                                           final OceanusDateRange pRange) {
540             /* Initialise class */
541             this(pAnalysis);
542 
543             /* Loop through the buckets */
544             final Iterator<MoneyWiseXAnalysisPayeeBucket> myIterator = pBase.iterator();
545             while (myIterator.hasNext()) {
546                 final MoneyWiseXAnalysisPayeeBucket myCurr = myIterator.next();
547 
548                 /* Access the bucket for this range */
549                 final MoneyWiseXAnalysisPayeeBucket myBucket = new MoneyWiseXAnalysisPayeeBucket(pAnalysis, myCurr, pRange);
550 
551                 /* If the bucket is non-idle */
552                 if (!myBucket.isIdle()) {
553                     /* Adjust to the base and add to the list */
554                     myBucket.adjustToBase();
555                     theList.add(myBucket);
556                 }
557             }
558         }
559 
560         @Override
561         public MetisFieldSet<MoneyWiseXAnalysisPayeeBucketList> getDataFieldSet() {
562             return FIELD_DEFS;
563         }
564 
565         @Override
566         public List<MoneyWiseXAnalysisPayeeBucket> getUnderlyingList() {
567             return theList.getUnderlyingList();
568         }
569 
570         @Override
571         public String formatObject(final OceanusDataFormatter pFormatter) {
572             return getDataFieldSet().getName();
573         }
574 
575         /**
576          * Obtain item by id.
577          *
578          * @param pId the id to lookup
579          * @return the item (or null if not present)
580          */
581         public MoneyWiseXAnalysisPayeeBucket findItemById(final Integer pId) {
582             /* Return results */
583             return theList.getItemById(pId);
584         }
585 
586         /**
587          * Obtain the analysis.
588          *
589          * @return the analysis
590          */
591         MoneyWiseXAnalysis getAnalysis() {
592             return theAnalysis;
593         }
594 
595         /**
596          * Obtain the Totals.
597          *
598          * @return the totals
599          */
600         public MoneyWiseXAnalysisPayeeBucket getTotals() {
601             return theTotals;
602         }
603 
604         /**
605          * Allocate the Totals PayeeBucket.
606          *
607          * @return the bucket
608          */
609         private MoneyWiseXAnalysisPayeeBucket allocateTotalsBucket() {
610             /* Obtain the totals payee */
611             return new MoneyWiseXAnalysisPayeeBucket(theAnalysis, null);
612         }
613 
614         /**
615          * Obtain the PayeeBucket for a given payee.
616          *
617          * @param pPayee the payee
618          * @return the bucket
619          */
620         public MoneyWiseXAnalysisPayeeBucket getBucket(final MoneyWiseAssetBase pPayee) {
621             /* Handle null payee */
622             if (pPayee == null) {
623                 return null;
624             }
625 
626             /* Access as payee */
627             final MoneyWisePayee myPayee = (MoneyWisePayee) pPayee;
628 
629             /* Locate the bucket in the list */
630             MoneyWiseXAnalysisPayeeBucket myItem = findItemById(myPayee.getIndexedId());
631 
632             /* If the item does not yet exist */
633             if (myItem == null) {
634                 /* Create the new bucket */
635                 myItem = new MoneyWiseXAnalysisPayeeBucket(theAnalysis, myPayee);
636 
637                 /* Add to the list */
638                 theList.add(myItem);
639             }
640 
641             /* Return the bucket */
642             return myItem;
643         }
644 
645         /**
646          * Obtain the PayeeBucket for a given payee class.
647          *
648          * @param pClass the account category class
649          * @return the bucket
650          */
651         public MoneyWiseXAnalysisPayeeBucket getBucket(final MoneyWisePayeeClass pClass) {
652             /* Determine required payee */
653             final MoneyWisePayee myPayee = theEditSet.getDataList(MoneyWiseBasicDataType.PAYEE, MoneyWisePayeeList.class).getSingularClass(pClass);
654 
655             /* Return the bucket */
656             return getBucket(myPayee);
657         }
658 
659         /**
660          * Obtain the matching PayeeBucket.
661          *
662          * @param pPayee the payee
663          * @return the matching bucket
664          */
665         public MoneyWiseXAnalysisPayeeBucket getMatchingPayee(final MoneyWisePayee pPayee) {
666             /* Return the matching payee if it exists else an orphan bucket */
667             final MoneyWiseXAnalysisPayeeBucket myPayee = findItemById(pPayee.getIndexedId());
668             return myPayee != null
669                     ? myPayee
670                     : new MoneyWiseXAnalysisPayeeBucket(theAnalysis, pPayee);
671         }
672 
673         /**
674          * Obtain the default PayeeBucket.
675          *
676          * @return the default bucket
677          */
678         public MoneyWiseXAnalysisPayeeBucket getDefaultPayee() {
679             /* Return the first payee in the list if it exists */
680             return isEmpty()
681                     ? null
682                     : theList.getUnderlyingList().get(0);
683         }
684 
685         /**
686          * Produce totals for the Payees.
687          */
688         public void produceTotals() {
689             /* Loop through the buckets */
690             final Iterator<MoneyWiseXAnalysisPayeeBucket> myIterator = iterator();
691             while (myIterator.hasNext()) {
692                 final MoneyWiseXAnalysisPayeeBucket myCurr = myIterator.next();
693 
694                 /* Remove idle items */
695                 if (myCurr.isIdle()) {
696                     myIterator.remove();
697                     continue;
698                 }
699 
700                 /* Calculate the delta */
701                 myCurr.calculateDelta();
702 
703                 /* Add to totals bucket */
704                 theTotals.addValues(myCurr);
705             }
706 
707             /* Sort the payees */
708             theList.sortList();
709 
710             /* Calculate delta for the totals */
711             if (theTotals != null) {
712                 theTotals.calculateDelta();
713             }
714         }
715     }
716 }