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.metis.data.MetisDataItem.MetisDataFieldId;
21  import io.github.tonywasher.joceanus.metis.data.MetisDataType;
22  import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseDataException;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataInfoClass;
24  
25  /**
26   * Enumeration of Account Info Classes.
27   */
28  public enum MoneyWiseAccountInfoClass
29          implements PrometheusDataInfoClass, MetisDataFieldId {
30      /**
31       * Maturity Date.
32       */
33      MATURITY(1, 0, MetisDataType.DATE),
34  
35      /**
36       * Opening Balance.
37       */
38      OPENINGBALANCE(2, 1, MetisDataType.MONEY),
39  
40      /**
41       * AutoExpense Category.
42       */
43      AUTOEXPENSE(3, 2, MetisDataType.LINK),
44  
45      /**
46       * AutoExpense Payee.
47       */
48      AUTOPAYEE(4, 3, MetisDataType.LINK),
49  
50      /**
51       * WebSite.
52       */
53      WEBSITE(5, 4, MetisDataType.CHARARRAY),
54  
55      /**
56       * Customer #.
57       */
58      CUSTOMERNO(6, 5, MetisDataType.CHARARRAY),
59  
60      /**
61       * User Id.
62       */
63      USERID(7, 6, MetisDataType.CHARARRAY),
64  
65      /**
66       * Password.
67       */
68      PASSWORD(8, 7, MetisDataType.CHARARRAY),
69  
70      /**
71       * SortCode.
72       */
73      SORTCODE(9, 8, MetisDataType.CHARARRAY),
74  
75      /**
76       * Account.
77       */
78      ACCOUNT(10, 9, MetisDataType.CHARARRAY),
79  
80      /**
81       * Reference.
82       */
83      REFERENCE(11, 10, MetisDataType.CHARARRAY),
84  
85      /**
86       * Notes.
87       */
88      NOTES(12, 11, MetisDataType.CHARARRAY),
89  
90      /**
91       * Symbol.
92       */
93      SYMBOL(13, 12, MetisDataType.STRING),
94  
95      /**
96       * Region.
97       */
98      REGION(14, 13, MetisDataType.LINK),
99  
100     /**
101      * UnderlyingStock.
102      */
103     UNDERLYINGSTOCK(15, 14, MetisDataType.LINK),
104 
105     /**
106      * OptionPrice.
107      */
108     OPTIONPRICE(16, 15, MetisDataType.PRICE);
109 
110     /**
111      * The String name.
112      */
113     private String theName;
114 
115     /**
116      * Class Id.
117      */
118     private final int theId;
119 
120     /**
121      * Class Order.
122      */
123     private final int theOrder;
124 
125     /**
126      * Data Type.
127      */
128     private final MetisDataType theDataType;
129 
130     /**
131      * Constructor.
132      *
133      * @param uId       the Id
134      * @param uOrder    the default order.
135      * @param pDataType the data type
136      */
137     MoneyWiseAccountInfoClass(final int uId,
138                               final int uOrder,
139                               final MetisDataType pDataType) {
140         theId = uId;
141         theOrder = uOrder;
142         theDataType = pDataType;
143     }
144 
145     @Override
146     public int getClassId() {
147         return theId;
148     }
149 
150     @Override
151     public int getOrder() {
152         return theOrder;
153     }
154 
155     @Override
156     public MetisDataType getDataType() {
157         return theDataType;
158     }
159 
160     @Override
161     public boolean isLink() {
162         return theDataType == MetisDataType.LINK;
163     }
164 
165     @Override
166     public boolean isLinkSet() {
167         return false;
168     }
169 
170     @Override
171     public String toString() {
172         /* If we have not yet loaded the name */
173         if (theName == null) {
174             /* Load the name */
175             theName = MoneyWiseStaticResource.getKeyForAccountInfo(this).getValue();
176         }
177 
178         /* return the name */
179         return theName;
180     }
181 
182     /**
183      * get value from id.
184      *
185      * @param id the id value
186      * @return the corresponding enum object
187      * @throws OceanusException on error
188      */
189     public static MoneyWiseAccountInfoClass fromId(final int id) throws OceanusException {
190         for (MoneyWiseAccountInfoClass myClass : values()) {
191             if (myClass.getClassId() == id) {
192                 return myClass;
193             }
194         }
195         throw new MoneyWiseDataException("Invalid ClassId for " + MoneyWiseStaticDataType.ACCOUNTINFOTYPE.toString() + ":" + id);
196     }
197 
198     /**
199      * Obtain maximum length for infoType.
200      *
201      * @return the maximum length
202      */
203     public int getMaximumLength() {
204         switch (this) {
205             case WEBSITE:
206                 return MoneyWiseAccountInfoType.WEBSITE_LEN;
207             case CUSTOMERNO:
208             case USERID:
209             case PASSWORD:
210             case SORTCODE:
211             case ACCOUNT:
212             case REFERENCE:
213                 return MoneyWiseAccountInfoType.DATA_LEN;
214             case NOTES:
215                 return MoneyWiseAccountInfoType.NOTES_LEN;
216             case SYMBOL:
217                 return MoneyWiseSecurityType.SYMBOL_LEN;
218             default:
219                 return 0;
220         }
221     }
222 
223     @Override
224     public String getId() {
225         return toString();
226     }
227 }