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