1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.moneywise.data.statics;
18
19 import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataFieldId;
20 import io.github.tonywasher.joceanus.metis.data.MetisDataType;
21 import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseDataException;
22 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
23 import io.github.tonywasher.joceanus.oceanus.resource.OceanusBundleId;
24 import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataInfoClass;
25
26
27
28
29 public enum MoneyWiseAccountInfoClass
30 implements PrometheusDataInfoClass, MetisDataFieldId {
31
32
33
34 MATURITY(1, 0, MetisDataType.DATE),
35
36
37
38
39 OPENINGBALANCE(2, 1, MetisDataType.MONEY),
40
41
42
43
44 AUTOEXPENSE(3, 2, MetisDataType.LINK),
45
46
47
48
49 AUTOPAYEE(4, 3, MetisDataType.LINK),
50
51
52
53
54 WEBSITE(5, 4, MetisDataType.CHARARRAY),
55
56
57
58
59 CUSTOMERNO(6, 5, MetisDataType.CHARARRAY),
60
61
62
63
64 USERID(7, 6, MetisDataType.CHARARRAY),
65
66
67
68
69 PASSWORD(8, 7, MetisDataType.CHARARRAY),
70
71
72
73
74 SORTCODE(9, 8, MetisDataType.CHARARRAY),
75
76
77
78
79 ACCOUNT(10, 9, MetisDataType.CHARARRAY),
80
81
82
83
84 REFERENCE(11, 10, MetisDataType.CHARARRAY),
85
86
87
88
89 NOTES(12, 11, MetisDataType.CHARARRAY),
90
91
92
93
94 SYMBOL(13, 12, MetisDataType.STRING),
95
96
97
98
99 REGION(14, 13, MetisDataType.LINK),
100
101
102
103
104 UNDERLYINGSTOCK(15, 14, MetisDataType.LINK),
105
106
107
108
109 OPTIONPRICE(16, 15, MetisDataType.PRICE);
110
111
112
113
114 private static final int WEBSITE_LEN = 50;
115
116
117
118
119 private static final int DATA_LEN = 20;
120
121
122
123
124 private static final int NOTES_LEN = 500;
125
126
127
128
129 private String theName;
130
131
132
133
134 private final int theId;
135
136
137
138
139 private final int theOrder;
140
141
142
143
144 private final MetisDataType theDataType;
145
146
147
148
149
150
151
152
153 MoneyWiseAccountInfoClass(final int uId,
154 final int uOrder,
155 final MetisDataType pDataType) {
156 theId = uId;
157 theOrder = uOrder;
158 theDataType = pDataType;
159 }
160
161 @Override
162 public int getClassId() {
163 return theId;
164 }
165
166 @Override
167 public int getOrder() {
168 return theOrder;
169 }
170
171 @Override
172 public MetisDataType getDataType() {
173 return theDataType;
174 }
175
176 @Override
177 public boolean isLink() {
178 return theDataType == MetisDataType.LINK;
179 }
180
181 @Override
182 public boolean isLinkSet() {
183 return false;
184 }
185
186 @Override
187 public String toString() {
188
189 if (theName == null) {
190
191 theName = bundleIdForInfoClass(this).getValue();
192 }
193
194
195 return theName;
196 }
197
198
199
200
201
202
203
204
205 public static MoneyWiseAccountInfoClass fromId(final int id) throws OceanusException {
206 for (MoneyWiseAccountInfoClass myClass : values()) {
207 if (myClass.getClassId() == id) {
208 return myClass;
209 }
210 }
211 throw new MoneyWiseDataException("Invalid ClassId for " + MoneyWiseStaticDataType.ACCOUNTINFOTYPE.toString() + ":" + id);
212 }
213
214
215
216
217
218
219 public int getMaximumLength() {
220 return switch (this) {
221 case WEBSITE -> WEBSITE_LEN;
222 case CUSTOMERNO, USERID, PASSWORD, SORTCODE, ACCOUNT, REFERENCE -> DATA_LEN;
223 case NOTES -> NOTES_LEN;
224 case SYMBOL -> MoneyWiseSecurityType.SYMBOL_LEN;
225 default -> 0;
226 };
227 }
228
229 @Override
230 public String getId() {
231 return toString();
232 }
233
234
235
236
237
238
239
240 private static OceanusBundleId bundleIdForInfoClass(final MoneyWiseAccountInfoClass pClass) {
241
242 return switch (pClass) {
243 case MATURITY -> MoneyWiseStaticResource.ACCOUNTINFO_MATURITY;
244 case OPENINGBALANCE -> MoneyWiseStaticResource.ACCOUNTINFO_OPENING;
245 case AUTOEXPENSE -> MoneyWiseStaticResource.ACCOUNTINFO_AUTOEXPENSE;
246 case AUTOPAYEE -> MoneyWiseStaticResource.ACCOUNTINFO_AUTOPAYEE;
247 case WEBSITE -> MoneyWiseStaticResource.ACCOUNTINFO_WEBSITE;
248 case CUSTOMERNO -> MoneyWiseStaticResource.ACCOUNTINFO_CUSTNO;
249 case USERID -> MoneyWiseStaticResource.ACCOUNTINFO_USERID;
250 case PASSWORD -> MoneyWiseStaticResource.ACCOUNTINFO_PASSWORD;
251 case SORTCODE -> MoneyWiseStaticResource.ACCOUNTINFO_SORTCODE;
252 case ACCOUNT -> MoneyWiseStaticResource.ACCOUNTINFO_ACCOUNT;
253 case REFERENCE -> MoneyWiseStaticResource.ACCOUNTINFO_REFERENCE;
254 case NOTES -> MoneyWiseStaticResource.ACCOUNTINFO_NOTES;
255 case REGION -> MoneyWiseStaticResource.ACCOUNTINFO_REGION;
256 case SYMBOL -> MoneyWiseStaticResource.ACCOUNTINFO_SYMBOL;
257 case UNDERLYINGSTOCK -> MoneyWiseStaticResource.ACCOUNTINFO_UNDERLYINGSTOCK;
258 case OPTIONPRICE -> MoneyWiseStaticResource.ACCOUNTINFO_OPTIONPRICE;
259 default -> throw new IllegalArgumentException();
260 };
261 }
262 }