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   * PayeeAttribute enumeration.
25   */
26  public enum MoneyWiseXAnalysisPayeeAttr
27          implements MoneyWiseXAnalysisAttribute {
28      /**
29       * Income.
30       */
31      INCOME,
32  
33      /**
34       * Expense.
35       */
36      EXPENSE,
37  
38      /**
39       * Profit (NetIncome).
40       */
41      PROFIT;
42  
43      /**
44       * The String name.
45       */
46      private String theName;
47  
48      @Override
49      public String toString() {
50          /* If we have not yet loaded the name */
51          if (theName == null) {
52              /* Load the name */
53              theName = bundleIdForAttribute(this).getValue();
54          }
55  
56          /* return the name */
57          return theName;
58      }
59  
60      @Override
61      public boolean isPreserved() {
62          return true;
63      }
64  
65      @Override
66      public MetisDataType getDataType() {
67          return MetisDataType.MONEY;
68      }
69  
70      /**
71       * Obtain the resource bundleId for the attribute.
72       *
73       * @param pAttr the attribute
74       * @return the resource bundleId
75       */
76      private static OceanusBundleId bundleIdForAttribute(final MoneyWiseXAnalysisPayeeAttr pAttr) {
77          return switch (pAttr) {
78              case INCOME -> MoneyWiseXAnalysisValuesResource.PAYEEATTR_INCOME;
79              case EXPENSE -> MoneyWiseXAnalysisValuesResource.PAYEEATTR_EXPENSE;
80              case PROFIT -> MoneyWiseXAnalysisValuesResource.ACCOUNTATTR_PROFIT;
81              default -> throw new IllegalArgumentException();
82          };
83      }
84  }