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 Portfolio Type Classes.
25 */
26 public enum MoneyWisePortfolioClass
27 implements PrometheusStaticDataClass {
28 /**
29 * Standard.
30 * <p>
31 * This is a standard portfolio.
32 */
33 STANDARD(1, 0),
34
35 /**
36 * ISA.
37 * <p>
38 * This is a TaxFree portfolio.
39 */
40 TAXFREE(2, 1),
41
42 /**
43 * Pension.
44 * <p>
45 * This is a Pension. and is singular
46 */
47 PENSION(3, 2),
48
49 /**
50 * SIPP.
51 * <p>
52 * This is a SIPP Portfolio.
53 */
54 SIPP(4, 3);
55
56 /**
57 * The String name.
58 */
59 private String theName;
60
61 /**
62 * Class Id.
63 */
64 private final int theId;
65
66 /**
67 * Class Order.
68 */
69 private final int theOrder;
70
71 /**
72 * Constructor.
73 *
74 * @param uId the Id
75 * @param uOrder the default order.
76 */
77 MoneyWisePortfolioClass(final int uId,
78 final int uOrder) {
79 theId = uId;
80 theOrder = uOrder;
81 }
82
83 @Override
84 public int getClassId() {
85 return theId;
86 }
87
88 @Override
89 public int getOrder() {
90 return theOrder;
91 }
92
93 @Override
94 public String toString() {
95 /* If we have not yet loaded the name */
96 if (theName == null) {
97 /* Load the name */
98 theName = MoneyWiseStaticResource.getKeyForPortfolioType(this).getValue();
99 }
100
101 /* return the name */
102 return theName;
103 }
104
105 /**
106 * get value from id.
107 *
108 * @param id the id value
109 * @return the corresponding enum object
110 * @throws OceanusException on error
111 */
112 public static MoneyWisePortfolioClass fromId(final int id) throws OceanusException {
113 for (MoneyWisePortfolioClass myClass : values()) {
114 if (myClass.getClassId() == id) {
115 return myClass;
116 }
117 }
118 throw new MoneyWiseDataException("Invalid ClassId for " + MoneyWiseStaticDataType.PORTFOLIOTYPE.toString() + ":" + id);
119 }
120
121 /**
122 * Determine whether the PortfolioType is tax free.
123 *
124 * @return <code>true</code> if the PortfolioTtype is tax free, <code>false</code> otherwise.
125 */
126 public boolean isTaxFree() {
127 return this != STANDARD;
128 }
129
130 /**
131 * Determine whether the PortfolioType is a pension.
132 *
133 * @return <code>true</code> if the PortfolioType is pension, <code>false</code> otherwise.
134 */
135 public boolean isPension() {
136 switch (this) {
137 case PENSION:
138 case SIPP:
139 return true;
140 default:
141 return false;
142 }
143 }
144
145 /**
146 * Determine whether the PortfolioType owns securities.
147 *
148 * @return <code>true</code> if the PortfolioType owns securities, <code>false</code> otherwise.
149 */
150 public boolean holdsSecurities() {
151 switch (this) {
152 case STANDARD:
153 case TAXFREE:
154 case SIPP:
155 return true;
156 default:
157 return false;
158 }
159 }
160
161 /**
162 * Determine whether the PortfolioType can hold pension securities.
163 *
164 * @return <code>true</code> if the PortfolioType owns pensions, <code>false</code> otherwise.
165 */
166 public boolean holdsPensions() {
167 return this == PENSION;
168 }
169
170 /**
171 * Is this a singular portfolio?.
172 *
173 * @return <code>true</code> if the PortfolioType is singular, <code>false</code> otherwise.
174 */
175 public boolean isSingular() {
176 return holdsPensions();
177 }
178 }