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   * PayeeValues class.
26   */
27  public final class MoneyWiseAnalysisPayeeValues
28          extends MoneyWiseAnalysisValues<MoneyWiseAnalysisPayeeValues, MoneyWiseAnalysisPayeeAttr> {
29      /**
30       * Constructor.
31       *
32       * @param pCurrency the reporting currency
33       */
34      public MoneyWiseAnalysisPayeeValues(final Currency pCurrency) {
35          /* Initialise class */
36          super(MoneyWiseAnalysisPayeeAttr.class);
37  
38          /* Initialise income/expense to zero */
39          super.setValue(MoneyWiseAnalysisPayeeAttr.INCOME, new OceanusMoney(pCurrency));
40          super.setValue(MoneyWiseAnalysisPayeeAttr.EXPENSE, new OceanusMoney(pCurrency));
41      }
42  
43      /**
44       * Constructor.
45       *
46       * @param pSource       the source map.
47       * @param pCountersOnly only copy counters
48       */
49      public MoneyWiseAnalysisPayeeValues(final MoneyWiseAnalysisPayeeValues pSource,
50                                          final boolean pCountersOnly) {
51          /* Initialise class */
52          super(pSource, pCountersOnly);
53      }
54  
55      @Override
56      protected MoneyWiseAnalysisPayeeValues getCounterSnapShot() {
57          return new MoneyWiseAnalysisPayeeValues(this, true);
58      }
59  
60      @Override
61      protected MoneyWiseAnalysisPayeeValues getFullSnapShot() {
62          return new MoneyWiseAnalysisPayeeValues(this, false);
63      }
64  
65      @Override
66      public void adjustToBaseValues(final MoneyWiseAnalysisPayeeValues pBase) {
67          /* Adjust income/expense values */
68          adjustMoneyToBase(pBase, MoneyWiseAnalysisPayeeAttr.INCOME);
69          adjustMoneyToBase(pBase, MoneyWiseAnalysisPayeeAttr.EXPENSE);
70          calculateDelta();
71      }
72  
73      @Override
74      public void resetBaseValues() {
75          /* Create a zero value in the correct currency */
76          OceanusMoney myValue = getMoneyValue(MoneyWiseAnalysisPayeeAttr.INCOME);
77          myValue = new OceanusMoney(myValue);
78          myValue.setZero();
79  
80          /* Reset Income and expense values */
81          super.setValue(MoneyWiseAnalysisPayeeAttr.INCOME, myValue);
82          super.setValue(MoneyWiseAnalysisPayeeAttr.EXPENSE, new OceanusMoney(myValue));
83          super.setValue(MoneyWiseAnalysisPayeeAttr.PROFIT, new OceanusMoney(myValue));
84      }
85  
86      /**
87       * Calculate delta.
88       */
89      public void calculateDelta() {
90          /* Obtain a copy of the value */
91          OceanusMoney myDelta = getMoneyValue(MoneyWiseAnalysisPayeeAttr.INCOME);
92          myDelta = new OceanusMoney(myDelta);
93  
94          /* Subtract the expense value */
95          final OceanusMoney myExpense = getMoneyValue(MoneyWiseAnalysisPayeeAttr.EXPENSE);
96          myDelta.subtractAmount(myExpense);
97  
98          /* Set the delta */
99          super.setValue(MoneyWiseAnalysisPayeeAttr.PROFIT, myDelta);
100     }
101 
102     /**
103      * Are the values?
104      *
105      * @return true/false
106      */
107     public boolean isActive() {
108         final OceanusMoney myIncome = getMoneyValue(MoneyWiseAnalysisPayeeAttr.INCOME);
109         final OceanusMoney myExpense = getMoneyValue(MoneyWiseAnalysisPayeeAttr.EXPENSE);
110         return myIncome.isNonZero() || myExpense.isNonZero();
111     }
112 }
113