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.values;
18  
19  import io.github.tonywasher.joceanus.metis.data.MetisDataType;
20  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.base.MoneyWiseXAnalysisAttribute;
21  import io.github.tonywasher.joceanus.oceanus.resource.OceanusBundleId;
22  
23  /**
24   * AccountAttribute enumeration.
25   */
26  public enum MoneyWiseXAnalysisAccountAttr
27          implements MoneyWiseXAnalysisAttribute {
28      /**
29       * Local Currency Balance.
30       */
31      BALANCE,
32  
33      /**
34       * Exchange Rate.
35       */
36      EXCHANGERATE,
37  
38      /**
39       * Reported Valuation.
40       */
41      VALUATION,
42  
43      /**
44       * Valuation Delta.
45       */
46      VALUEDELTA,
47  
48      /**
49       * Deposit Rate.
50       */
51      DEPOSITRATE,
52  
53      /**
54       * Maturity.
55       */
56      MATURITY;
57  
58      /**
59       * The String name.
60       */
61      private String theName;
62  
63      @Override
64      public String toString() {
65          /* If we have not yet loaded the name */
66          if (theName == null) {
67              /* Load the name */
68              theName = bundleIdForAttribute(this).getValue();
69          }
70  
71          /* return the name */
72          return theName;
73      }
74  
75      @Override
76      public boolean isPreserved() {
77          return switch (this) {
78              case BALANCE, MATURITY, DEPOSITRATE, EXCHANGERATE, VALUATION -> true;
79              default -> false;
80          };
81      }
82  
83      @Override
84      public MetisDataType getDataType() {
85          return switch (this) {
86              case DEPOSITRATE -> MetisDataType.RATE;
87              case EXCHANGERATE -> MetisDataType.RATIO;
88              case MATURITY -> MetisDataType.DATE;
89              default -> MetisDataType.MONEY;
90          };
91      }
92  
93      /**
94       * Obtain the resource bundleId for the attribute.
95       *
96       * @param pAttr the attribute
97       * @return the resource bundleId
98       */
99      private static OceanusBundleId bundleIdForAttribute(final MoneyWiseXAnalysisAccountAttr pAttr) {
100         return switch (pAttr) {
101             case BALANCE -> MoneyWiseXAnalysisValuesResource.ACCOUNTATTR_BALANCE;
102             case VALUATION -> MoneyWiseXAnalysisValuesResource.ACCOUNTATTR_VALUATION;
103             case VALUEDELTA -> MoneyWiseXAnalysisValuesResource.ACCOUNTATTR_VALUEDELTA;
104             case DEPOSITRATE -> MoneyWiseXAnalysisValuesResource.ACCOUNTATTR_DEPOSITRATE;
105             case EXCHANGERATE -> MoneyWiseXAnalysisValuesResource.ACCOUNTATTR_EXCHANGERATE;
106             case MATURITY -> MoneyWiseXAnalysisValuesResource.ACCOUNTATTR_MATURITY;
107             default -> throw new IllegalArgumentException();
108         };
109     }
110 }