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