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.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   * Analysis Event.
45   */
46  public class MoneyWiseXAnalysisEvent
47          extends PrometheusDataItem {
48      /**
49       * Local Report fields.
50       */
51      static final MetisFieldSet<MoneyWiseXAnalysisEvent> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseXAnalysisEvent.class);
52  
53      /*
54       * FieldIds.
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       * Non-transaction indicator.
68       */
69      private static final int NONTRANS = 0x40000000;
70  
71      /**
72       * EventType.
73       */
74      private final MoneyWiseXAnalysisEventType theEventType;
75  
76      /**
77       * Transaction.
78       */
79      private final MoneyWiseTransaction theTransaction;
80  
81      /**
82       * The Date.
83       */
84      private final OceanusDate theDate;
85  
86      /**
87       * The securityPrice List.
88       */
89      private final List<MoneyWiseSecurityPrice> thePrices;
90  
91      /**
92       * The exchangeRate List.
93       */
94      private final List<MoneyWiseExchangeRate> theXchgRates;
95  
96      /**
97       * The depositRate List.
98       */
99      private final List<MoneyWiseNewDepositRate> theDepRates;
100 
101     /**
102      * The opening balance list.
103      */
104     private final List<MoneyWiseAssetBase> theBalances;
105 
106     /**
107      * Transaction constructor.
108      *
109      * @param pList  the owning list
110      * @param pTrans the transaction.
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      * Event constructor.
126      *
127      * @param pList      the owning list
128      * @param pEventType the eventType.
129      * @param pDate      the date
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      * Determine the id of a non-transaction event.
151      *
152      * @param pEventType the eventType
153      * @param pDate      the date
154      * @return the id
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      * Obtain the event type.
174      *
175      * @return the eventType
176      */
177     public MoneyWiseXAnalysisEventType getEventType() {
178         return theEventType;
179     }
180 
181     /**
182      * Obtain the transaction.
183      *
184      * @return the transaction
185      */
186     public MoneyWiseTransaction getTransaction() {
187         return theTransaction;
188     }
189 
190     /**
191      * Obtain the priceList.
192      *
193      * @return the priceList
194      */
195     private List<MoneyWiseSecurityPrice> getPrices() {
196         return thePrices;
197     }
198 
199     /**
200      * Obtain the xchgRateList.
201      *
202      * @return the xchgRateList
203      */
204     private List<MoneyWiseExchangeRate> getXchgRates() {
205         return theXchgRates;
206     }
207 
208     /**
209      * Obtain the depositRateList.
210      *
211      * @return the depositRateList
212      */
213     private List<MoneyWiseNewDepositRate> getDepRates() {
214         return theDepRates;
215     }
216 
217     /**
218      * Obtain the openingBalanceList.
219      *
220      * @return the openingBalanceList
221      */
222     private List<MoneyWiseAssetBase> getBalances() {
223         return theBalances;
224     }
225 
226     @Override
227     public int compareTo(final Object pThat) {
228         /* Handle the trivial cases */
229         if (this.equals(pThat)) {
230             return 0;
231         }
232         if (pThat == null) {
233             return -1;
234         }
235 
236         /* Non-DataItems are last */
237         if (!(pThat instanceof MoneyWiseXAnalysisEvent)) {
238             return -1;
239         }
240 
241         /* Check date and then data type */
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         /* Only event types with same date are transactions */
252         return theTransaction == null ? 0 : theTransaction.compareTo(myThat.getTransaction());
253     }
254 
255     @Override
256     protected int compareValues(final PrometheusDataItem pThat) {
257         /* Check date and then data type */
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         /* Only event types with same date are transactions */
268         return theTransaction == null ? 0 : theTransaction.compareTo(myThat.getTransaction());
269     }
270 
271     @Override
272     public boolean equals(final Object pThat) {
273         /* Handle trivial cases */
274         if (this == pThat) {
275             return true;
276         } else if (!(pThat instanceof MoneyWiseXAnalysisEvent)) {
277             return false;
278         }
279 
280         /* Access object correctly */
281         final MoneyWiseXAnalysisEvent myThat = (MoneyWiseXAnalysisEvent) pThat;
282 
283         /* Ensure date is identical */
284         if (!theDate.equals(myThat.getDate())) {
285             return false;
286         }
287 
288         /* Ensure eventType is identical */
289         if (theEventType != myThat.getEventType()) {
290             return false;
291         }
292 
293         /* Check transaction */
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      * declare securityPrice.
304      *
305      * @param pPrice the security Price.
306      */
307     public void declareSecurityPrice(final MoneyWiseSecurityPrice pPrice) {
308         if (thePrices != null) {
309             thePrices.add(pPrice);
310         }
311     }
312 
313     /**
314      * declare exchangeRate.
315      *
316      * @param pRate the exchangeRate.
317      */
318     public void declareExchangeRate(final MoneyWiseExchangeRate pRate) {
319         if (theXchgRates != null) {
320             theXchgRates.add(pRate);
321         }
322     }
323 
324     /**
325      * declare depositRate.
326      *
327      * @param pRate the depositRate.
328      */
329     public void declareDepositRate(final MoneyWiseNewDepositRate pRate) {
330         if (theDepRates != null) {
331             theDepRates.add(pRate);
332         }
333     }
334 
335     /**
336      * declare opening balance.
337      *
338      * @param pAsset the asset.
339      */
340     public void declareOpeningBalance(final MoneyWiseAssetBase pAsset) {
341         if (theBalances != null) {
342             theBalances.add(pAsset);
343         }
344     }
345 
346     /**
347      * obtain the securityPrice iterator.
348      *
349      * @return the iterator.
350      */
351     public Iterator<MoneyWiseSecurityPrice> priceIterator() {
352         return thePrices != null ? thePrices.iterator() : Collections.emptyIterator();
353     }
354 
355     /**
356      * obtain the exchangeRate iterator.
357      *
358      * @return the iterator.
359      */
360     public Iterator<MoneyWiseExchangeRate> xchgRateIterator() {
361         return theXchgRates != null ? theXchgRates.iterator() : Collections.emptyIterator();
362     }
363 
364     /**
365      * obtain the depositRate iterator.
366      *
367      * @return the iterator.
368      */
369     public Iterator<MoneyWiseNewDepositRate> depRateIterator() {
370         return theDepRates != null ? theDepRates.iterator() : Collections.emptyIterator();
371     }
372 
373     /**
374      * obtain the openingBalance iterator.
375      *
376      * @return the iterator.
377      */
378     public Iterator<MoneyWiseAssetBase> balanceIterator() {
379         return theBalances != null ? theBalances.iterator() : Collections.emptyIterator();
380     }
381 
382     /**
383      * Obtain the date.
384      *
385      * @return the date
386      */
387     public OceanusDate getDate() {
388         return theDate;
389     }
390 
391     /**
392      * Set the date.
393      *
394      * @param pDate the date
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      * Obtain the account.
409      *
410      * @return the account
411      */
412     public MoneyWiseTransAsset getAccount() {
413         return theTransaction == null ? null : theTransaction.getAccount();
414     }
415 
416     /**
417      * Set the account.
418      *
419      * @param pAccount the account
420      */
421     public void setAccount(final MoneyWiseTransAsset pAccount) {
422         if (theTransaction != null) {
423             theTransaction.setAccount(pAccount);
424         }
425     }
426 
427     /**
428      * Obtain the category.
429      *
430      * @return the category
431      */
432     public MoneyWiseTransCategory getCategory() {
433         return theTransaction == null ? null : theTransaction.getCategory();
434     }
435 
436     /**
437      * Set the category.
438      *
439      * @param pCategory the category
440      */
441     public void setCategory(final MoneyWiseTransCategory pCategory) {
442         if (theTransaction != null) {
443             theTransaction.setCategory(pCategory);
444         }
445     }
446 
447     /**
448      * Obtain the direction.
449      *
450      * @return the direction
451      */
452     public MoneyWiseAssetDirection getDirection() {
453         return theTransaction == null ? null : theTransaction.getDirection();
454     }
455 
456     /**
457      * Set the direction.
458      *
459      * @param pDirection the direction
460      */
461     public void setDirection(final MoneyWiseAssetDirection pDirection) {
462         if (theTransaction != null) {
463             theTransaction.setDirection(pDirection);
464         }
465     }
466 
467     /**
468      * Obtain the partner.
469      *
470      * @return the partner
471      */
472     public MoneyWiseTransAsset getPartner() {
473         return theTransaction == null ? null : theTransaction.getPartner();
474     }
475 
476     /**
477      * Set the partner.
478      *
479      * @param pPartner the partner
480      */
481     public void setPartner(final MoneyWiseTransAsset pPartner) {
482         if (theTransaction != null) {
483             theTransaction.setPartner(pPartner);
484         }
485     }
486 
487     /**
488      * Obtain the amount.
489      *
490      * @return the amount
491      */
492     public OceanusMoney getAmount() {
493         return theTransaction == null ? null : theTransaction.getAmount();
494     }
495 
496     /**
497      * Set the amount.
498      *
499      * @param pAmount the amount
500      * @throws OceanusException on error
501      */
502     public void setAmount(final OceanusMoney pAmount) throws OceanusException {
503         if (theTransaction != null) {
504             theTransaction.setAmount(pAmount);
505         }
506     }
507 
508     /**
509      * is the event reconciled?
510      *
511      * @return true/false
512      */
513     public Boolean isReconciled() {
514         return theTransaction == null ? Boolean.TRUE : theTransaction.isReconciled();
515     }
516 
517     /**
518      * Set the reconciled.
519      *
520      * @param pReconciled the reconciled flag
521      */
522     public void setReconciled(final Boolean pReconciled) {
523         if (theTransaction != null) {
524             theTransaction.setReconciled(pReconciled);
525         }
526     }
527 
528     /**
529      * Obtain the comment.
530      *
531      * @return the comment
532      */
533     public String getComments() {
534         return theTransaction == null ? null : theTransaction.getComments();
535     }
536 
537     /**
538      * Set the comment.
539      *
540      * @param pComment the comment
541      * @throws OceanusException on error
542      */
543     public void setComments(final String pComment) throws OceanusException {
544         if (theTransaction != null) {
545             theTransaction.setComments(pComment);
546         }
547     }
548 
549     /**
550      * Obtain the reference.
551      *
552      * @return the reference
553      */
554     public String getReference() {
555         return theTransaction == null ? null : theTransaction.getReference();
556     }
557 
558     /**
559      * Set the reference.
560      *
561      * @param pReference the reference
562      * @throws OceanusException on error
563      */
564     public void setReference(final String pReference) throws OceanusException {
565         if (theTransaction != null) {
566             theTransaction.setReference(pReference);
567         }
568     }
569 
570     /**
571      * Obtain the taxCredit.
572      *
573      * @return the taxCredit
574      */
575     public OceanusMoney getTaxCredit() {
576         return theTransaction == null ? null : theTransaction.getTaxCredit();
577     }
578 
579     /**
580      * Set the taxCredit.
581      *
582      * @param pCredit the taxCredit
583      * @throws OceanusException on error
584      */
585     public void setTaxCredit(final OceanusMoney pCredit) throws OceanusException {
586         if (theTransaction != null) {
587             theTransaction.setTaxCredit(pCredit);
588         }
589     }
590 
591     /**
592      * Obtain the employeesNI.
593      *
594      * @return the employeesNI
595      */
596     public OceanusMoney getEmployeeNatIns() {
597         return theTransaction == null ? null : theTransaction.getEmployeeNatIns();
598     }
599 
600     /**
601      * Set the employeeNI.
602      *
603      * @param pNatIns the employeeNI
604      * @throws OceanusException on error
605      */
606     public void setEmployeeNatIns(final OceanusMoney pNatIns) throws OceanusException {
607         if (theTransaction != null) {
608             theTransaction.setEmployeeNatIns(pNatIns);
609         }
610     }
611 
612     /**
613      * Obtain the employerNI.
614      *
615      * @return the employerNI
616      */
617     public OceanusMoney getEmployerNatIns() {
618         return theTransaction == null ? null : theTransaction.getEmployerNatIns();
619     }
620 
621     /**
622      * Set the employerNI.
623      *
624      * @param pNatIns the employerNI
625      * @throws OceanusException on error
626      */
627     public void setEmployerNatIns(final OceanusMoney pNatIns) throws OceanusException {
628         if (theTransaction != null) {
629             theTransaction.setEmployerNatIns(pNatIns);
630         }
631     }
632 
633     /**
634      * Obtain the deemedBenefit.
635      *
636      * @return the deemedBenefit
637      */
638     public OceanusMoney getDeemedBenefit() {
639         return theTransaction == null ? null : theTransaction.getDeemedBenefit();
640     }
641 
642     /**
643      * Set the deemedBenefit.
644      *
645      * @param pBenefit the benefit
646      * @throws OceanusException on error
647      */
648     public void setDeemedBenefit(final OceanusMoney pBenefit) throws OceanusException {
649         if (theTransaction != null) {
650             theTransaction.setDeemedBenefit(pBenefit);
651         }
652     }
653 
654     /**
655      * Obtain the withheld.
656      *
657      * @return the withheld
658      */
659     public OceanusMoney getWithheld() {
660         return theTransaction == null ? null : theTransaction.getWithheld();
661     }
662 
663     /**
664      * Set the withheld.
665      *
666      * @param pWithheld the withheld
667      * @throws OceanusException on error
668      */
669     public void setWithheld(final OceanusMoney pWithheld) throws OceanusException {
670         if (theTransaction != null) {
671             theTransaction.setWithheld(pWithheld);
672         }
673     }
674 
675     /**
676      * Obtain the partnerAmount.
677      *
678      * @return the partnerAmount
679      */
680     public OceanusMoney getPartnerAmount() {
681         return theTransaction == null ? null : theTransaction.getPartnerAmount();
682     }
683 
684     /**
685      * Set the partnerAmount.
686      *
687      * @param pAmount the amount
688      * @throws OceanusException on error
689      */
690     public void setPartnerAmount(final OceanusMoney pAmount) throws OceanusException {
691         if (theTransaction != null) {
692             theTransaction.setEmployeeNatIns(pAmount);
693         }
694     }
695 
696     /**
697      * Obtain the returnedCashAccount.
698      *
699      * @return the returnedCashAccount
700      */
701     public MoneyWiseTransAsset getReturnedCashAccount() {
702         return theTransaction == null ? null : theTransaction.getReturnedCashAccount();
703     }
704 
705     /**
706      * Set the returnedCashAccount.
707      *
708      * @param pAccount the returnedCashAccount
709      * @throws OceanusException on error
710      */
711     public void setReturnedCashAccount(final MoneyWiseTransAsset pAccount) throws OceanusException {
712         if (theTransaction != null) {
713             theTransaction.setReturnedCashAccount(pAccount);
714         }
715     }
716 
717     /**
718      * Obtain the returnedCash.
719      *
720      * @return the returnedCash
721      */
722     public OceanusMoney getReturnedCash() {
723         return theTransaction == null ? null : theTransaction.getReturnedCash();
724     }
725 
726     /**
727      * Set the returnedCash.
728      *
729      * @param pAmount the amount
730      * @throws OceanusException on error
731      */
732     public void setReturnedCash(final OceanusMoney pAmount) throws OceanusException {
733         if (theTransaction != null) {
734             theTransaction.setReturnedCash(pAmount);
735         }
736     }
737 
738     /**
739      * Obtain the accountDeltaUnits.
740      *
741      * @return the accountDeltaUnits
742      */
743     public OceanusUnits getAccountDeltaUnits() {
744         return theTransaction == null ? null : theTransaction.getAccountDeltaUnits();
745     }
746 
747     /**
748      * Set the accountDeltaUnits.
749      *
750      * @param pDelta the deltaUnits
751      * @throws OceanusException on error
752      */
753     public void setAccountDeltaUnits(final OceanusUnits pDelta) throws OceanusException {
754         if (theTransaction != null) {
755             theTransaction.setAccountDeltaUnits(pDelta);
756         }
757     }
758 
759     /**
760      * Obtain the partnerDeltaUnits.
761      *
762      * @return the partnerDeltaUnits
763      */
764     public OceanusUnits getPartnerDeltaUnits() {
765         return theTransaction == null ? null : theTransaction.getPartnerDeltaUnits();
766     }
767 
768     /**
769      * Set the partnerDeltaUnits.
770      *
771      * @param pDelta the deltaUnits
772      * @throws OceanusException on error
773      */
774     public void setPartnerDeltaUnits(final OceanusUnits pDelta) throws OceanusException {
775         if (theTransaction != null) {
776             theTransaction.setPartnerDeltaUnits(pDelta);
777         }
778     }
779 
780     /**
781      * Obtain the dilution.
782      *
783      * @return the dilution
784      */
785     public OceanusRatio getDilution() {
786         return theTransaction == null ? null : theTransaction.getDilution();
787     }
788 
789     /**
790      * Set the dilution.
791      *
792      * @param pDilution the dilution
793      * @throws OceanusException on error
794      */
795     public void setDilution(final OceanusRatio pDilution) throws OceanusException {
796         if (theTransaction != null) {
797             theTransaction.setDilution(pDilution);
798         }
799     }
800 
801     /**
802      * Obtain the transactionTags.
803      *
804      * @return the transactionTags
805      */
806     public List<MoneyWiseTransTag> getTransactionTags() {
807         return theTransaction == null ? null : theTransaction.getTransactionTags();
808     }
809 
810     /**
811      * Set the transactionTags.
812      *
813      * @param pTags the tags
814      * @throws OceanusException on error
815      */
816     public void setTransactionTags(final List<MoneyWiseTransTag> pTags) throws OceanusException {
817         if (theTransaction != null) {
818             theTransaction.setTransactionTags(pTags);
819         }
820     }
821 
822     /**
823      * Switch direction.
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      * Determines whether we can switch direction.
843      *
844      * @return true/false
845      */
846     public boolean canSwitchDirection() {
847         return theTransaction != null && theTransaction.canSwitchDirection();
848     }
849 
850     /**
851      * Obtain EventInfo.
852      *
853      * @param pInfoClass the infoClass
854      * @return the Info
855      */
856     public Object getEventInfo(final MoneyWiseTransInfoClass pInfoClass) {
857         /* No info unless this is a transaction */
858         if (theTransaction == null) {
859             return null;
860         }
861 
862         /* Obtain the relevant info */
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 }