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.data.statics;
18  
19  import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseDataException;
20  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
21  import io.github.tonywasher.joceanus.oceanus.resource.OceanusBundleId;
22  import io.github.tonywasher.joceanus.prometheus.data.PrometheusStaticDataClass;
23  
24  /**
25   * Enumeration of Tax Basis Classes.
26   */
27  public enum MoneyWiseTaxClass
28          implements PrometheusStaticDataClass {
29      /**
30       * Salary Income.
31       */
32      SALARY(1, 0),
33  
34      /**
35       * RoomRental.
36       */
37      ROOMRENTAL(2, 1),
38  
39      /**
40       * Rental Income.
41       */
42      RENTALINCOME(3, 2),
43  
44      /**
45       * Other Income.
46       */
47      OTHERINCOME(4, 3),
48  
49      /**
50       * Taxed Interest Income.
51       */
52      TAXEDINTEREST(5, 4),
53  
54      /**
55       * UnTaxed Interest Income.
56       */
57      UNTAXEDINTEREST(6, 5),
58  
59      /**
60       * Peer2PeerInterest.
61       */
62      PEER2PEERINTEREST(7, 6),
63  
64      /**
65       * Dividend Income.
66       */
67      DIVIDEND(8, 7),
68  
69      /**
70       * Unit Trust Dividend Income.
71       */
72      UNITTRUSTDIVIDEND(9, 8),
73  
74      /**
75       * Foreign Dividend Income.
76       */
77      FOREIGNDIVIDEND(10, 9),
78  
79      /**
80       * Chargeable gains.
81       */
82      CHARGEABLEGAINS(11, 10),
83  
84      /**
85       * Residential gains.
86       */
87      RESIDENTIALGAINS(12, 11),
88  
89      /**
90       * Capital gains.
91       */
92      CAPITALGAINS(13, 12),
93  
94      /**
95       * Tax Free Income.
96       */
97      TAXFREE(14, 13),
98  
99      /**
100      * Market Growth.
101      */
102     MARKET(15, 14),
103 
104     /**
105      * Total Tax Paid.
106      */
107     TAXPAID(16, 15),
108 
109     /**
110      * Gross Expense.
111      */
112     EXPENSE(17, 16),
113 
114     /**
115      * Virtual Income.
116      */
117     VIRTUAL(18, 17);
118 
119     /**
120      * The String name.
121      */
122     private String theName;
123 
124     /**
125      * Class Id.
126      */
127     private final int theId;
128 
129     /**
130      * Class Order.
131      */
132     private final int theOrder;
133 
134     /**
135      * Constructor.
136      *
137      * @param uId    the id
138      * @param uOrder the order
139      */
140     MoneyWiseTaxClass(final int uId,
141                       final int uOrder) {
142         /* Set values */
143         theId = uId;
144         theOrder = uOrder;
145     }
146 
147     @Override
148     public int getClassId() {
149         return theId;
150     }
151 
152     @Override
153     public int getOrder() {
154         return theOrder;
155     }
156 
157     @Override
158     public String toString() {
159         /* If we have not yet loaded the name */
160         if (theName == null) {
161             /* Load the name */
162             theName = bundleIdForTaxClass(this).getValue();
163         }
164 
165         /* return the name */
166         return theName;
167     }
168 
169     /**
170      * get value from id.
171      *
172      * @param id the id value
173      * @return the corresponding enum object
174      * @throws OceanusException on error
175      */
176     public static MoneyWiseTaxClass fromId(final int id) throws OceanusException {
177         for (MoneyWiseTaxClass myClass : values()) {
178             if (myClass.getClassId() == id) {
179                 return myClass;
180             }
181         }
182         throw new MoneyWiseDataException("Invalid ClassId for " + MoneyWiseStaticDataType.TAXBASIS.toString() + ":" + id);
183     }
184 
185     /**
186      * Should we analyse accounts?
187      *
188      * @return true/false
189      */
190     public boolean analyseAccounts() {
191         return switch (this) {
192             case SALARY, ROOMRENTAL, RENTALINCOME, OTHERINCOME, TAXEDINTEREST, UNTAXEDINTEREST, DIVIDEND,
193                  UNITTRUSTDIVIDEND, FOREIGNDIVIDEND, CHARGEABLEGAINS, CAPITALGAINS, RESIDENTIALGAINS, TAXFREE,
194                  PEER2PEERINTEREST -> true;
195             default -> false;
196         };
197     }
198 
199     /**
200      * Is the basis an expense basis?
201      *
202      * @return true/false
203      */
204     public boolean isExpense() {
205         return switch (this) {
206             case EXPENSE, TAXPAID, VIRTUAL -> true;
207             default -> false;
208         };
209     }
210 
211     /**
212      * Obtain the resource bundleId for the tax class.
213      *
214      * @param pClass the tax class
215      * @return the resource bundleId
216      */
217     private static OceanusBundleId bundleIdForTaxClass(final MoneyWiseTaxClass pClass) {
218         /* Create the map and return it */
219         return switch (pClass) {
220             case SALARY -> MoneyWiseStaticResource.TAXBASIS_SALARY;
221             case ROOMRENTAL -> MoneyWiseStaticResource.TAXBASIS_ROOMRENTAL;
222             case RENTALINCOME -> MoneyWiseStaticResource.TAXBASIS_RENTALINCOME;
223             case OTHERINCOME -> MoneyWiseStaticResource.TAXBASIS_OTHERINCOME;
224             case TAXEDINTEREST -> MoneyWiseStaticResource.TAXBASIS_TAXEDINTEREST;
225             case UNTAXEDINTEREST -> MoneyWiseStaticResource.TAXBASIS_UNTAXEDINTEREST;
226             case DIVIDEND -> MoneyWiseStaticResource.TAXBASIS_DIVIDEND;
227             case UNITTRUSTDIVIDEND -> MoneyWiseStaticResource.TAXBASIS_UTDIVIDEND;
228             case FOREIGNDIVIDEND -> MoneyWiseStaticResource.TAXBASIS_FOREIGNDIVIDEND;
229             case CHARGEABLEGAINS -> MoneyWiseStaticResource.TAXBASIS_CHARGEABLEGAINS;
230             case RESIDENTIALGAINS -> MoneyWiseStaticResource.TAXBASIS_RESIDENTIALGAINS;
231             case CAPITALGAINS -> MoneyWiseStaticResource.TAXBASIS_CAPITALGAINS;
232             case PEER2PEERINTEREST -> MoneyWiseStaticResource.TRANSTYPE_PEER2PEERINTEREST;
233             case TAXPAID -> MoneyWiseStaticResource.TAXBASIS_TAXPAID;
234             case MARKET -> MoneyWiseStaticResource.TAXBASIS_MARKET;
235             case TAXFREE -> MoneyWiseStaticResource.TAXBASIS_TAXFREE;
236             case EXPENSE -> MoneyWiseStaticResource.TAXBASIS_EXPENSE;
237             case VIRTUAL -> MoneyWiseStaticResource.TAXBASIS_VIRTUAL;
238             default -> throw new IllegalArgumentException();
239         };
240     }
241 }