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 CashCategory Type Classes.
24 */
25 public enum MoneyWiseCashCategoryClass
26 implements MoneyWiseCategoryInterface {
27 /**
28 * Cash Account.
29 * <p>
30 * This is a cash account and represents cash that is held by the client outside of any
31 * institution.
32 */
33 CASH(1, 1),
34
35 /**
36 * AutoExpense Cash Account.
37 * <p>
38 * This is a cash account and represents cash that is held by the client outside of any
39 * institution.
40 */
41 AUTOEXPENSE(2, 2),
42
43 /**
44 * Parent Category.
45 * <p>
46 * This is used as a sub-total bucket and is used purely for reporting purposes.
47 */
48 PARENT(3, 0);
49
50 /**
51 * The String name.
52 */
53 private String theName;
54
55 /**
56 * Class Id.
57 */
58 private final int theId;
59
60 /**
61 * Class Order.
62 */
63 private final int theOrder;
64
65 /**
66 * Constructor.
67 *
68 * @param uId the Id
69 * @param uOrder the default order.
70 */
71 MoneyWiseCashCategoryClass(final int uId,
72 final int uOrder) {
73 theId = uId;
74 theOrder = uOrder;
75 }
76
77 @Override
78 public int getClassId() {
79 return theId;
80 }
81
82 @Override
83 public int getOrder() {
84 return theOrder;
85 }
86
87 @Override
88 public String toString() {
89 /* If we have not yet loaded the name */
90 if (theName == null) {
91 /* Load the name */
92 theName = MoneyWiseStaticResource.getKeyForCashType(this).getValue();
93 }
94
95 /* return the name */
96 return theName;
97 }
98
99 /**
100 * get value from id.
101 *
102 * @param id the id value
103 * @return the corresponding enum object
104 * @throws OceanusException on error
105 */
106 public static MoneyWiseCashCategoryClass fromId(final int id) throws OceanusException {
107 for (MoneyWiseCashCategoryClass myClass : values()) {
108 if (myClass.getClassId() == id) {
109 return myClass;
110 }
111 }
112 throw new MoneyWiseDataException("Invalid ClassId for " + MoneyWiseStaticDataType.CASHTYPE.toString() + ":" + id);
113 }
114
115 /**
116 * Determine whether the CashCategoryType is a parent category.
117 *
118 * @return <code>true</code> if the cash category type is a parent category, <code>false</code>
119 * otherwise.
120 */
121 public boolean isParentCategory() {
122 switch (this) {
123 case PARENT:
124 return true;
125 default:
126 return false;
127 }
128 }
129
130 @Override
131 public boolean isTotals() {
132 return false;
133 }
134 }