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.lethe.data.analysis.values;
18  
19  import io.github.tonywasher.joceanus.oceanus.decimal.OceanusMoney;
20  import io.github.tonywasher.joceanus.moneywise.lethe.data.analysis.base.MoneyWiseAnalysisValues;
21  
22  import java.util.Currency;
23  
24  /**
25   * AccountValues class.
26   */
27  public class MoneyWiseAnalysisAccountValues
28          extends MoneyWiseAnalysisValues<MoneyWiseAnalysisAccountValues, MoneyWiseAnalysisAccountAttr> {
29      /**
30       * Constructor.
31       *
32       * @param pCurrency the account currency
33       */
34      public MoneyWiseAnalysisAccountValues(final Currency pCurrency) {
35          /* Initialise class */
36          super(MoneyWiseAnalysisAccountAttr.class);
37  
38          /* Initialise valuation to zero */
39          super.setValue(MoneyWiseAnalysisAccountAttr.VALUATION, new OceanusMoney(pCurrency));
40      }
41  
42      /**
43       * Constructor.
44       *
45       * @param pCurrency          the account currency
46       * @param pReportingCurrency the reporting currency
47       */
48      public MoneyWiseAnalysisAccountValues(final Currency pCurrency,
49                                            final Currency pReportingCurrency) {
50          /* Initialise class */
51          this(pReportingCurrency);
52  
53          /* Initialise valuation to zero */
54          super.setValue(MoneyWiseAnalysisAccountAttr.FOREIGNVALUE, new OceanusMoney(pCurrency));
55          super.setValue(MoneyWiseAnalysisAccountAttr.LOCALVALUE, new OceanusMoney(pReportingCurrency));
56          super.setValue(MoneyWiseAnalysisAccountAttr.CURRENCYFLUCT, new OceanusMoney(pReportingCurrency));
57      }
58  
59      /**
60       * Constructor.
61       *
62       * @param pSource       the source map.
63       * @param pCountersOnly only copy counters
64       */
65      protected MoneyWiseAnalysisAccountValues(final MoneyWiseAnalysisAccountValues pSource,
66                                               final boolean pCountersOnly) {
67          /* Initialise class */
68          super(pSource, pCountersOnly);
69      }
70  
71      @Override
72      protected MoneyWiseAnalysisAccountValues getCounterSnapShot() {
73          return new MoneyWiseAnalysisAccountValues(this, true);
74      }
75  
76      @Override
77      protected MoneyWiseAnalysisAccountValues getFullSnapShot() {
78          return new MoneyWiseAnalysisAccountValues(this, false);
79      }
80  
81      /**
82       * Are the values active?
83       *
84       * @return true/false
85       */
86      public boolean isActive() {
87          final OceanusMoney myValuation = getMoneyValue(MoneyWiseAnalysisAccountAttr.VALUATION);
88          return myValuation != null && myValuation.isNonZero();
89      }
90  
91      @Override
92      public void adjustToBaseValues(final MoneyWiseAnalysisAccountValues pBase) {
93          /* If we have a currency fluctuation */
94          if (getMoneyValue(MoneyWiseAnalysisAccountAttr.CURRENCYFLUCT) != null) {
95              /* Adjust currency fluctuation values */
96              adjustMoneyToBase(pBase, MoneyWiseAnalysisAccountAttr.CURRENCYFLUCT);
97          }
98      }
99  
100     @Override
101     public void resetBaseValues() {
102         /* If we have a currency fluctuation */
103         OceanusMoney myValue = getMoneyValue(MoneyWiseAnalysisAccountAttr.CURRENCYFLUCT);
104         if (myValue != null) {
105             /* Create zero value */
106             myValue = new OceanusMoney(myValue);
107             myValue.setZero();
108 
109             /* Adjust currency fluctuation values */
110             super.setValue(MoneyWiseAnalysisAccountAttr.CURRENCYFLUCT, myValue);
111         }
112     }
113 }