1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.base;
18
19 import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
20 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseAssetBase;
21 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseAssetDirection;
22 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicResource;
23 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseExchangeRate;
24 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseSecurityPrice;
25 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseTransAsset;
26 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseTransCategory;
27 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseTransTag;
28 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseTransaction;
29 import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseTransInfoClass;
30 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
31 import io.github.tonywasher.joceanus.oceanus.date.OceanusDate;
32 import io.github.tonywasher.joceanus.oceanus.decimal.OceanusMoney;
33 import io.github.tonywasher.joceanus.oceanus.decimal.OceanusRatio;
34 import io.github.tonywasher.joceanus.oceanus.decimal.OceanusUnits;
35 import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataItem;
36 import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataList;
37
38 import java.util.ArrayList;
39 import java.util.Collections;
40 import java.util.Iterator;
41 import java.util.List;
42 import java.util.Objects;
43
44
45
46
47 public class MoneyWiseXAnalysisEvent
48 extends PrometheusDataItem {
49
50
51
52 static final MetisFieldSet<MoneyWiseXAnalysisEvent> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseXAnalysisEvent.class);
53
54
55
56
57 static {
58 FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBaseResource.EVENT_DATE, MoneyWiseXAnalysisEvent::getDate);
59 FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBaseResource.EVENT_TYPE, MoneyWiseXAnalysisEvent::getEventType);
60 FIELD_DEFS.declareLocalField(MoneyWiseBasicResource.TRANSACTION_NAME, MoneyWiseXAnalysisEvent::getTransaction);
61 FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBaseResource.EVENT_PRICES, MoneyWiseXAnalysisEvent::getPrices);
62 FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBaseResource.EVENT_XCHGRATES, MoneyWiseXAnalysisEvent::getXchgRates);
63 FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBaseResource.EVENT_DEPRATES, MoneyWiseXAnalysisEvent::getDepRates);
64 FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBaseResource.EVENT_BALANCES, MoneyWiseXAnalysisEvent::getBalances);
65 }
66
67
68
69
70 private static final int NONTRANS = 0x40000000;
71
72
73
74
75 private final MoneyWiseXAnalysisEventType theEventType;
76
77
78
79
80 private final MoneyWiseTransaction theTransaction;
81
82
83
84
85 private final OceanusDate theDate;
86
87
88
89
90 private final List<MoneyWiseSecurityPrice> thePrices;
91
92
93
94
95 private final List<MoneyWiseExchangeRate> theXchgRates;
96
97
98
99
100 private final List<MoneyWiseNewDepositRate> theDepRates;
101
102
103
104
105 private final List<MoneyWiseAssetBase> theBalances;
106
107
108
109
110
111
112
113 public MoneyWiseXAnalysisEvent(final PrometheusDataList<MoneyWiseXAnalysisEvent> pList,
114 final MoneyWiseTransaction pTrans) {
115 super(pList, pTrans.getIndexedId());
116 theEventType = MoneyWiseXAnalysisEventType.TRANSACTION;
117 theTransaction = pTrans;
118 theDate = pTrans.getDate();
119 thePrices = null;
120 theXchgRates = null;
121 theDepRates = null;
122 theBalances = null;
123 }
124
125
126
127
128
129
130
131
132 public MoneyWiseXAnalysisEvent(final PrometheusDataList<MoneyWiseXAnalysisEvent> pList,
133 final MoneyWiseXAnalysisEventType pEventType,
134 final OceanusDate pDate) {
135 super(pList, determineId(pEventType, pDate));
136 theEventType = pEventType;
137 theTransaction = null;
138 theDate = pDate;
139 thePrices = MoneyWiseXAnalysisEventType.SECURITYPRICE == theEventType ? new ArrayList<>() : null;
140 theXchgRates = MoneyWiseXAnalysisEventType.XCHANGERATE == theEventType ? new ArrayList<>() : null;
141 theDepRates = MoneyWiseXAnalysisEventType.DEPOSITRATE == theEventType ? new ArrayList<>() : null;
142 theBalances = MoneyWiseXAnalysisEventType.OPENINGBALANCE == theEventType ? new ArrayList<>() : null;
143 }
144
145 @Override
146 public MetisFieldSetDef getDataFieldSet() {
147 return FIELD_DEFS;
148 }
149
150
151
152
153
154
155
156
157 private static Integer determineId(final MoneyWiseXAnalysisEventType pEventType,
158 final OceanusDate pDate) {
159 final int myId = NONTRANS + (pDate.getId() << 2);
160 return switch (pEventType) {
161 case SECURITYPRICE -> myId - 1;
162 case XCHANGERATE -> myId;
163 case DEPOSITRATE -> myId + 1;
164 default -> myId + 2;
165 };
166 }
167
168
169
170
171
172
173 public MoneyWiseXAnalysisEventType getEventType() {
174 return theEventType;
175 }
176
177
178
179
180
181
182 public MoneyWiseTransaction getTransaction() {
183 return theTransaction;
184 }
185
186
187
188
189
190
191 private List<MoneyWiseSecurityPrice> getPrices() {
192 return thePrices;
193 }
194
195
196
197
198
199
200 private List<MoneyWiseExchangeRate> getXchgRates() {
201 return theXchgRates;
202 }
203
204
205
206
207
208
209 private List<MoneyWiseNewDepositRate> getDepRates() {
210 return theDepRates;
211 }
212
213
214
215
216
217
218 private List<MoneyWiseAssetBase> getBalances() {
219 return theBalances;
220 }
221
222 @Override
223 public int compareTo(final Object pThat) {
224
225 if (this.equals(pThat)) {
226 return 0;
227 }
228 if (pThat == null) {
229 return -1;
230 }
231
232
233 if (!(pThat instanceof MoneyWiseXAnalysisEvent)) {
234 return -1;
235 }
236
237
238 final MoneyWiseXAnalysisEvent myThat = (MoneyWiseXAnalysisEvent) pThat;
239 final int iDiff = theDate.compareTo(myThat.getDate());
240 if (iDiff != 0) {
241 return iDiff;
242 }
243 if (theEventType != myThat.getEventType()) {
244 return theEventType.compareTo(myThat.getEventType());
245 }
246
247
248 return theTransaction == null ? 0 : theTransaction.compareTo(myThat.getTransaction());
249 }
250
251 @Override
252 protected int compareValues(final PrometheusDataItem pThat) {
253
254 final MoneyWiseXAnalysisEvent myThat = (MoneyWiseXAnalysisEvent) pThat;
255 final int iDiff = theDate.compareTo(myThat.getDate());
256 if (iDiff != 0) {
257 return iDiff;
258 }
259 if (theEventType != myThat.getEventType()) {
260 return theEventType.compareTo(myThat.getEventType());
261 }
262
263
264 return theTransaction == null ? 0 : theTransaction.compareTo(myThat.getTransaction());
265 }
266
267 @Override
268 public boolean equals(final Object pThat) {
269
270 if (this == pThat) {
271 return true;
272 } else if (!(pThat instanceof MoneyWiseXAnalysisEvent)) {
273 return false;
274 }
275
276
277 final MoneyWiseXAnalysisEvent myThat = (MoneyWiseXAnalysisEvent) pThat;
278
279
280 if (!theDate.equals(myThat.getDate())) {
281 return false;
282 }
283
284
285 if (theEventType != myThat.getEventType()) {
286 return false;
287 }
288
289
290 return Objects.equals(theTransaction, myThat.getTransaction());
291 }
292
293 @Override
294 public int hashCode() {
295 return Objects.hash(theDate, theEventType, theTransaction);
296 }
297
298
299
300
301
302
303 public void declareSecurityPrice(final MoneyWiseSecurityPrice pPrice) {
304 if (thePrices != null) {
305 thePrices.add(pPrice);
306 }
307 }
308
309
310
311
312
313
314 public void declareExchangeRate(final MoneyWiseExchangeRate pRate) {
315 if (theXchgRates != null) {
316 theXchgRates.add(pRate);
317 }
318 }
319
320
321
322
323
324
325 public void declareDepositRate(final MoneyWiseNewDepositRate pRate) {
326 if (theDepRates != null) {
327 theDepRates.add(pRate);
328 }
329 }
330
331
332
333
334
335
336 public void declareOpeningBalance(final MoneyWiseAssetBase pAsset) {
337 if (theBalances != null) {
338 theBalances.add(pAsset);
339 }
340 }
341
342
343
344
345
346
347 public Iterator<MoneyWiseSecurityPrice> priceIterator() {
348 return thePrices != null ? thePrices.iterator() : Collections.emptyIterator();
349 }
350
351
352
353
354
355
356 public Iterator<MoneyWiseExchangeRate> xchgRateIterator() {
357 return theXchgRates != null ? theXchgRates.iterator() : Collections.emptyIterator();
358 }
359
360
361
362
363
364
365 public Iterator<MoneyWiseNewDepositRate> depRateIterator() {
366 return theDepRates != null ? theDepRates.iterator() : Collections.emptyIterator();
367 }
368
369
370
371
372
373
374 public Iterator<MoneyWiseAssetBase> balanceIterator() {
375 return theBalances != null ? theBalances.iterator() : Collections.emptyIterator();
376 }
377
378
379
380
381
382
383 public OceanusDate getDate() {
384 return theDate;
385 }
386
387
388
389
390
391
392 public void setDate(final OceanusDate pDate) {
393 if (theTransaction != null) {
394 theTransaction.setDate(pDate);
395 }
396 }
397
398 @Override
399 public boolean isHeader() {
400 return theTransaction != null && theTransaction.isHeader();
401 }
402
403
404
405
406
407
408 public MoneyWiseTransAsset getAccount() {
409 return theTransaction == null ? null : theTransaction.getAccount();
410 }
411
412
413
414
415
416
417 public void setAccount(final MoneyWiseTransAsset pAccount) {
418 if (theTransaction != null) {
419 theTransaction.setAccount(pAccount);
420 }
421 }
422
423
424
425
426
427
428 public MoneyWiseTransCategory getCategory() {
429 return theTransaction == null ? null : theTransaction.getCategory();
430 }
431
432
433
434
435
436
437 public void setCategory(final MoneyWiseTransCategory pCategory) {
438 if (theTransaction != null) {
439 theTransaction.setCategory(pCategory);
440 }
441 }
442
443
444
445
446
447
448 public MoneyWiseAssetDirection getDirection() {
449 return theTransaction == null ? null : theTransaction.getDirection();
450 }
451
452
453
454
455
456
457 public void setDirection(final MoneyWiseAssetDirection pDirection) {
458 if (theTransaction != null) {
459 theTransaction.setDirection(pDirection);
460 }
461 }
462
463
464
465
466
467
468 public MoneyWiseTransAsset getPartner() {
469 return theTransaction == null ? null : theTransaction.getPartner();
470 }
471
472
473
474
475
476
477 public void setPartner(final MoneyWiseTransAsset pPartner) {
478 if (theTransaction != null) {
479 theTransaction.setPartner(pPartner);
480 }
481 }
482
483
484
485
486
487
488 public OceanusMoney getAmount() {
489 return theTransaction == null ? null : theTransaction.getAmount();
490 }
491
492
493
494
495
496
497
498 public void setAmount(final OceanusMoney pAmount) throws OceanusException {
499 if (theTransaction != null) {
500 theTransaction.setAmount(pAmount);
501 }
502 }
503
504
505
506
507
508
509 public Boolean isReconciled() {
510 return theTransaction == null ? Boolean.TRUE : theTransaction.isReconciled();
511 }
512
513
514
515
516
517
518 public void setReconciled(final Boolean pReconciled) {
519 if (theTransaction != null) {
520 theTransaction.setReconciled(pReconciled);
521 }
522 }
523
524
525
526
527
528
529 public String getComments() {
530 return theTransaction == null ? null : theTransaction.getComments();
531 }
532
533
534
535
536
537
538
539 public void setComments(final String pComment) throws OceanusException {
540 if (theTransaction != null) {
541 theTransaction.setComments(pComment);
542 }
543 }
544
545
546
547
548
549
550 public String getReference() {
551 return theTransaction == null ? null : theTransaction.getReference();
552 }
553
554
555
556
557
558
559
560 public void setReference(final String pReference) throws OceanusException {
561 if (theTransaction != null) {
562 theTransaction.setReference(pReference);
563 }
564 }
565
566
567
568
569
570
571 public OceanusMoney getTaxCredit() {
572 return theTransaction == null ? null : theTransaction.getTaxCredit();
573 }
574
575
576
577
578
579
580
581 public void setTaxCredit(final OceanusMoney pCredit) throws OceanusException {
582 if (theTransaction != null) {
583 theTransaction.setTaxCredit(pCredit);
584 }
585 }
586
587
588
589
590
591
592 public OceanusMoney getEmployeeNatIns() {
593 return theTransaction == null ? null : theTransaction.getEmployeeNatIns();
594 }
595
596
597
598
599
600
601
602 public void setEmployeeNatIns(final OceanusMoney pNatIns) throws OceanusException {
603 if (theTransaction != null) {
604 theTransaction.setEmployeeNatIns(pNatIns);
605 }
606 }
607
608
609
610
611
612
613 public OceanusMoney getEmployerNatIns() {
614 return theTransaction == null ? null : theTransaction.getEmployerNatIns();
615 }
616
617
618
619
620
621
622
623 public void setEmployerNatIns(final OceanusMoney pNatIns) throws OceanusException {
624 if (theTransaction != null) {
625 theTransaction.setEmployerNatIns(pNatIns);
626 }
627 }
628
629
630
631
632
633
634 public OceanusMoney getDeemedBenefit() {
635 return theTransaction == null ? null : theTransaction.getDeemedBenefit();
636 }
637
638
639
640
641
642
643
644 public void setDeemedBenefit(final OceanusMoney pBenefit) throws OceanusException {
645 if (theTransaction != null) {
646 theTransaction.setDeemedBenefit(pBenefit);
647 }
648 }
649
650
651
652
653
654
655 public OceanusMoney getWithheld() {
656 return theTransaction == null ? null : theTransaction.getWithheld();
657 }
658
659
660
661
662
663
664
665 public void setWithheld(final OceanusMoney pWithheld) throws OceanusException {
666 if (theTransaction != null) {
667 theTransaction.setWithheld(pWithheld);
668 }
669 }
670
671
672
673
674
675
676 public OceanusMoney getPartnerAmount() {
677 return theTransaction == null ? null : theTransaction.getPartnerAmount();
678 }
679
680
681
682
683
684
685
686 public void setPartnerAmount(final OceanusMoney pAmount) throws OceanusException {
687 if (theTransaction != null) {
688 theTransaction.setEmployeeNatIns(pAmount);
689 }
690 }
691
692
693
694
695
696
697 public MoneyWiseTransAsset getReturnedCashAccount() {
698 return theTransaction == null ? null : theTransaction.getReturnedCashAccount();
699 }
700
701
702
703
704
705
706
707 public void setReturnedCashAccount(final MoneyWiseTransAsset pAccount) throws OceanusException {
708 if (theTransaction != null) {
709 theTransaction.setReturnedCashAccount(pAccount);
710 }
711 }
712
713
714
715
716
717
718 public OceanusMoney getReturnedCash() {
719 return theTransaction == null ? null : theTransaction.getReturnedCash();
720 }
721
722
723
724
725
726
727
728 public void setReturnedCash(final OceanusMoney pAmount) throws OceanusException {
729 if (theTransaction != null) {
730 theTransaction.setReturnedCash(pAmount);
731 }
732 }
733
734
735
736
737
738
739 public OceanusUnits getAccountDeltaUnits() {
740 return theTransaction == null ? null : theTransaction.getAccountDeltaUnits();
741 }
742
743
744
745
746
747
748
749 public void setAccountDeltaUnits(final OceanusUnits pDelta) throws OceanusException {
750 if (theTransaction != null) {
751 theTransaction.setAccountDeltaUnits(pDelta);
752 }
753 }
754
755
756
757
758
759
760 public OceanusUnits getPartnerDeltaUnits() {
761 return theTransaction == null ? null : theTransaction.getPartnerDeltaUnits();
762 }
763
764
765
766
767
768
769
770 public void setPartnerDeltaUnits(final OceanusUnits pDelta) throws OceanusException {
771 if (theTransaction != null) {
772 theTransaction.setPartnerDeltaUnits(pDelta);
773 }
774 }
775
776
777
778
779
780
781 public OceanusRatio getDilution() {
782 return theTransaction == null ? null : theTransaction.getDilution();
783 }
784
785
786
787
788
789
790
791 public void setDilution(final OceanusRatio pDilution) throws OceanusException {
792 if (theTransaction != null) {
793 theTransaction.setDilution(pDilution);
794 }
795 }
796
797
798
799
800
801
802 public List<MoneyWiseTransTag> getTransactionTags() {
803 return theTransaction == null ? null : theTransaction.getTransactionTags();
804 }
805
806
807
808
809
810
811
812 public void setTransactionTags(final List<MoneyWiseTransTag> pTags) throws OceanusException {
813 if (theTransaction != null) {
814 theTransaction.setTransactionTags(pTags);
815 }
816 }
817
818
819
820
821 public void switchDirection() {
822 if (theTransaction != null) {
823 theTransaction.switchDirection();
824 }
825 }
826
827 @Override
828 public int getNextVersion() {
829 return 0;
830 }
831
832 @Override
833 public boolean isLocked() {
834 return theTransaction == null || theTransaction.isLocked();
835 }
836
837
838
839
840
841
842 public boolean canSwitchDirection() {
843 return theTransaction != null && theTransaction.canSwitchDirection();
844 }
845
846
847
848
849
850
851
852 public Object getEventInfo(final MoneyWiseTransInfoClass pInfoClass) {
853
854 if (theTransaction == null) {
855 return null;
856 }
857
858
859 switch (pInfoClass) {
860 case TAXCREDIT:
861 return theTransaction.getTaxCredit();
862 case EMPLOYEENATINS:
863 return theTransaction.getEmployeeNatIns();
864 case EMPLOYERNATINS:
865 return theTransaction.getEmployerNatIns();
866 case DEEMEDBENEFIT:
867 return theTransaction.getDeemedBenefit();
868 case WITHHELD:
869 return theTransaction.getWithheld();
870 case ACCOUNTDELTAUNITS:
871 return theTransaction.getAccountDeltaUnits();
872 case PARTNERDELTAUNITS:
873 return theTransaction.getPartnerDeltaUnits();
874 case DILUTION:
875 return theTransaction.getDilution();
876 case PRICE:
877 return theTransaction.getPrice();
878 case RETURNEDCASH:
879 return theTransaction.getReturnedCash();
880 case RETURNEDCASHACCOUNT:
881 return theTransaction.getReturnedCashAccount();
882 case PARTNERAMOUNT:
883 return theTransaction.getPartnerAmount();
884 case REFERENCE:
885 return theTransaction.getReference();
886 case COMMENTS:
887 return theTransaction.getComments();
888 case TRANSTAG:
889 return theTransaction.getTransactionTags();
890 default:
891 return null;
892 }
893 }
894 }