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  
22  /**
23   * Enumeration of DepositCategory Type Classes.
24   */
25  public enum MoneyWiseDepositCategoryClass
26          implements MoneyWiseCategoryInterface {
27      /**
28       * Checking Deposit.
29       * <p>
30       * These are standard checking deposit accounts that hold money on behalf of the client. Each
31       * such account must be owned by a {@link MoneyWisePayeeClass#INSTITUTION} payee.
32       */
33      CHECKING(1, 1),
34  
35      /**
36       * Savings Deposit.
37       * <p>
38       * These are standard savings accounts that hold money on behalf of the client. There is no
39       * distinction as to whether they are easy access or restricted access. Each such account must
40       * be owned by a {@link MoneyWisePayeeClass#INSTITUTION} payee.
41       */
42      SAVINGS(2, 2),
43  
44      /**
45       * TaxFreeSavings.
46       * <p>
47       * This a bond account which is a specialised form of an {@link #SAVINGS} account. It has an
48       * associated maturity date for the account.
49       */
50      TAXFREESAVINGS(3, 3),
51  
52      /**
53       * Peer2Peer Deposit.
54       * <p>
55       * This a peer2peer account which is a specialised form of an {@link #SAVINGS} account.
56       * LoyaltyBonuses are allowed, and the tax situation varies.
57       */
58      PEER2PEER(4, 4),
59  
60      /**
61       * Bond Deposit.
62       * <p>
63       * This a bond account which is a specialised form of an {@link #SAVINGS} account. It has an
64       * associated maturity date for the account.
65       */
66      BOND(5, 5),
67  
68      /**
69       * Bond Deposit.
70       * <p>
71       * This a bond account which is a specialised form of an {@link #SAVINGS} account. It has an
72       * associated maturity date for the account.
73       */
74      TAXFREEBOND(6, 6),
75  
76      /**
77       * Parent Category.
78       * <p>
79       * This is used as a sub-total bucket and is used purely for reporting purposes.
80       */
81      PARENT(7, 0);
82  
83      /**
84       * The String name.
85       */
86      private String theName;
87  
88      /**
89       * Class Id.
90       */
91      private final int theId;
92  
93      /**
94       * Class Order.
95       */
96      private final int theOrder;
97  
98      /**
99       * Constructor.
100      *
101      * @param uId    the Id
102      * @param uOrder the default order.
103      */
104     MoneyWiseDepositCategoryClass(final int uId,
105                                   final int uOrder) {
106         theId = uId;
107         theOrder = uOrder;
108     }
109 
110     @Override
111     public int getClassId() {
112         return theId;
113     }
114 
115     @Override
116     public int getOrder() {
117         return theOrder;
118     }
119 
120     @Override
121     public String toString() {
122         /* If we have not yet loaded the name */
123         if (theName == null) {
124             /* Load the name */
125             theName = MoneyWiseStaticResource.getKeyForDepositType(this).getValue();
126         }
127 
128         /* return the name */
129         return theName;
130     }
131 
132     /**
133      * get value from id.
134      *
135      * @param id the id value
136      * @return the corresponding enum object
137      * @throws OceanusException on error
138      */
139     public static MoneyWiseDepositCategoryClass fromId(final int id) throws OceanusException {
140         for (MoneyWiseDepositCategoryClass myClass : values()) {
141             if (myClass.getClassId() == id) {
142                 return myClass;
143             }
144         }
145         throw new MoneyWiseDataException("Invalid ClassId for " + MoneyWiseStaticDataType.DEPOSITTYPE.toString() + ":" + id);
146     }
147 
148     /**
149      * Determine whether the DepositCategoryType is a child, and needs a parent.
150      *
151      * @return <code>true</code> if the deposit category type is a child, <code>false</code>
152      * otherwise.
153      */
154     public boolean isChild() {
155         switch (this) {
156             case CHECKING:
157             case SAVINGS:
158             case TAXFREESAVINGS:
159             case PEER2PEER:
160             case BOND:
161             case TAXFREEBOND:
162                 return true;
163             default:
164                 return false;
165         }
166     }
167 
168     /**
169      * Determine whether the DepositCategoryType is be tax free.
170      *
171      * @return <code>true</code> if the deposit category type is tax free, <code>false</code>
172      * otherwise.
173      */
174     public boolean isTaxFree() {
175         switch (this) {
176             case TAXFREESAVINGS:
177             case TAXFREEBOND:
178                 return true;
179             default:
180                 return false;
181         }
182     }
183 
184     /**
185      * Determine whether the DepositCategoryType has a maturity date.
186      *
187      * @return <code>true</code> if the deposit category type has maturity, <code>false</code>
188      * otherwise.
189      */
190     public boolean hasMaturity() {
191         switch (this) {
192             case BOND:
193             case TAXFREEBOND:
194                 return true;
195             default:
196                 return false;
197         }
198     }
199 
200     /**
201      * Determine whether the DepositCategoryType is gross.
202      *
203      * @return <code>true</code> if the deposit category type is gross, <code>false</code>
204      * otherwise.
205      */
206     public boolean isGross() {
207         return this == PEER2PEER;
208     }
209 
210     /**
211      * Determine whether the DepositCategoryType can provide cashBack.
212      *
213      * @return <code>true</code> if the deposit category type can provide cashBack
214      * <code>false</code> otherwise.
215      */
216     public boolean canCashBack() {
217         switch (this) {
218             case CHECKING:
219             case PEER2PEER:
220                 return true;
221             default:
222                 return false;
223         }
224     }
225 
226     /**
227      * Determine whether the DepositCategoryType can provide loyaltyBonus.
228      *
229      * @return <code>true</code> if the deposit category type can provide loyaltyBonus
230      * <code>false</code> otherwise.
231      */
232     public boolean canLoyaltyBonus() {
233         return this == PEER2PEER;
234     }
235 
236     /**
237      * Determine whether the DepositCategoryType is a parent category.
238      *
239      * @return <code>true</code> if the deposit category type is a parent category,
240      * <code>false</code> otherwise.
241      */
242     public boolean isParentCategory() {
243         return this == PARENT;
244     }
245 
246     @Override
247     public boolean isTotals() {
248         return false;
249     }
250 }