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.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   * Enumeration of Account Info Classes.
28   */
29  public enum MoneyWiseAccountInfoClass
30          implements PrometheusDataInfoClass, MetisDataFieldId {
31      /**
32       * Maturity Date.
33       */
34      MATURITY(1, 0, MetisDataType.DATE),
35  
36      /**
37       * Opening Balance.
38       */
39      OPENINGBALANCE(2, 1, MetisDataType.MONEY),
40  
41      /**
42       * AutoExpense Category.
43       */
44      AUTOEXPENSE(3, 2, MetisDataType.LINK),
45  
46      /**
47       * AutoExpense Payee.
48       */
49      AUTOPAYEE(4, 3, MetisDataType.LINK),
50  
51      /**
52       * WebSite.
53       */
54      WEBSITE(5, 4, MetisDataType.CHARARRAY),
55  
56      /**
57       * Customer #.
58       */
59      CUSTOMERNO(6, 5, MetisDataType.CHARARRAY),
60  
61      /**
62       * User Id.
63       */
64      USERID(7, 6, MetisDataType.CHARARRAY),
65  
66      /**
67       * Password.
68       */
69      PASSWORD(8, 7, MetisDataType.CHARARRAY),
70  
71      /**
72       * SortCode.
73       */
74      SORTCODE(9, 8, MetisDataType.CHARARRAY),
75  
76      /**
77       * Account.
78       */
79      ACCOUNT(10, 9, MetisDataType.CHARARRAY),
80  
81      /**
82       * Reference.
83       */
84      REFERENCE(11, 10, MetisDataType.CHARARRAY),
85  
86      /**
87       * Notes.
88       */
89      NOTES(12, 11, MetisDataType.CHARARRAY),
90  
91      /**
92       * Symbol.
93       */
94      SYMBOL(13, 12, MetisDataType.STRING),
95  
96      /**
97       * Region.
98       */
99      REGION(14, 13, MetisDataType.LINK),
100 
101     /**
102      * UnderlyingStock.
103      */
104     UNDERLYINGSTOCK(15, 14, MetisDataType.LINK),
105 
106     /**
107      * OptionPrice.
108      */
109     OPTIONPRICE(16, 15, MetisDataType.PRICE);
110 
111     /**
112      * WebSite length.
113      */
114     private static final int WEBSITE_LEN = 50;
115 
116     /**
117      * Data length.
118      */
119     private static final int DATA_LEN = 20;
120 
121     /**
122      * Notes length.
123      */
124     private static final int NOTES_LEN = 500;
125 
126     /**
127      * The String name.
128      */
129     private String theName;
130 
131     /**
132      * Class Id.
133      */
134     private final int theId;
135 
136     /**
137      * Class Order.
138      */
139     private final int theOrder;
140 
141     /**
142      * Data Type.
143      */
144     private final MetisDataType theDataType;
145 
146     /**
147      * Constructor.
148      *
149      * @param uId       the Id
150      * @param uOrder    the default order.
151      * @param pDataType the data type
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         /* If we have not yet loaded the name */
189         if (theName == null) {
190             /* Load the name */
191             theName = bundleIdForInfoClass(this).getValue();
192         }
193 
194         /* return the name */
195         return theName;
196     }
197 
198     /**
199      * get value from id.
200      *
201      * @param id the id value
202      * @return the corresponding enum object
203      * @throws OceanusException on error
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      * Obtain maximum length for infoType.
216      *
217      * @return the maximum length
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      * Obtain the resource bundleId for the info class.
236      *
237      * @param pClass the info class
238      * @return the resource bundleId
239      */
240     private static OceanusBundleId bundleIdForInfoClass(final MoneyWiseAccountInfoClass pClass) {
241         /* Create the map and return it */
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 }