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 TransactionInfo Classes..
27   */
28  public enum MoneyWiseTransInfoClass
29          implements PrometheusDataInfoClass, MetisDataFieldId {
30      /**
31       * Tax Credit.
32       */
33      TAXCREDIT(1, 0, MetisDataType.MONEY),
34  
35      /**
36       * Employer National Insurance.
37       */
38      EMPLOYERNATINS(2, 1, MetisDataType.MONEY),
39  
40      /**
41       * Employee National Insurance.
42       */
43      EMPLOYEENATINS(3, 2, MetisDataType.MONEY),
44  
45      /**
46       * Deemed Benefit.
47       */
48      DEEMEDBENEFIT(4, 3, MetisDataType.MONEY),
49  
50      /**
51       * QualifyingYears.
52       */
53      QUALIFYYEARS(5, 4, MetisDataType.INTEGER),
54  
55      /**
56       * Account Delta Units.
57       */
58      ACCOUNTDELTAUNITS(6, 5, MetisDataType.UNITS),
59  
60      /**
61       * Partner Delta Units.
62       */
63      PARTNERDELTAUNITS(7, 6, MetisDataType.UNITS),
64  
65      /**
66       * Dilution.
67       */
68      DILUTION(8, 7, MetisDataType.RATIO),
69  
70      /**
71       * Reference.
72       */
73      REFERENCE(9, 8, MetisDataType.STRING),
74  
75      /**
76       * Withheld.
77       */
78      WITHHELD(10, 9, MetisDataType.MONEY),
79  
80      /**
81       * Partner Amount.
82       */
83      PARTNERAMOUNT(11, 10, MetisDataType.MONEY),
84  
85      /**
86       * ThirdParty Amount.
87       */
88      RETURNEDCASH(12, 11, MetisDataType.MONEY),
89  
90      /**
91       * ReturnedCashAccount.
92       */
93      RETURNEDCASHACCOUNT(13, 12, MetisDataType.LINKPAIR),
94  
95      /**
96       * Comments.
97       */
98      COMMENTS(14, 13, MetisDataType.STRING),
99  
100     /**
101      * Price.
102      */
103     PRICE(15, 14, MetisDataType.PRICE),
104 
105     /**
106      * XchangeRate.
107      */
108     XCHANGERATE(16, 15, MetisDataType.RATIO),
109 
110     /**
111      * Commission.
112      */
113     COMMISSION(17, 16, MetisDataType.MONEY),
114 
115     /**
116      * TransactionTag.
117      */
118     TRANSTAG(18, 17, MetisDataType.LINKSET);
119 
120     /**
121      * The String name.
122      */
123     private String theName;
124 
125     /**
126      * Class Id.
127      */
128     private final int theId;
129 
130     /**
131      * Class Order.
132      */
133     private final int theOrder;
134 
135     /**
136      * Data Type.
137      */
138     private final MetisDataType theDataType;
139 
140     /**
141      * Constructor.
142      *
143      * @param uId       the id
144      * @param uOrder    the default order
145      * @param pDataType the data type
146      */
147     MoneyWiseTransInfoClass(final int uId,
148                             final int uOrder,
149                             final MetisDataType pDataType) {
150         theId = uId;
151         theOrder = uOrder;
152         theDataType = pDataType;
153     }
154 
155     @Override
156     public int getClassId() {
157         return theId;
158     }
159 
160     @Override
161     public int getOrder() {
162         return theOrder;
163     }
164 
165     @Override
166     public MetisDataType getDataType() {
167         return theDataType;
168     }
169 
170     @Override
171     public boolean isLink() {
172         switch (theDataType) {
173             case LINK:
174             case LINKPAIR:
175             case LINKSET:
176                 return true;
177             default:
178                 return false;
179         }
180     }
181 
182     @Override
183     public boolean isLinkSet() {
184         return theDataType == MetisDataType.LINKSET;
185     }
186 
187     @Override
188     public String toString() {
189         /* If we have not yet loaded the name */
190         if (theName == null) {
191             /* Load the name */
192             theName = MoneyWiseStaticResource.getKeyForTransInfo(this).getValue();
193         }
194 
195         /* return the name */
196         return theName;
197     }
198 
199     /**
200      * get value from id.
201      *
202      * @param id the id value
203      * @return the corresponding enum object
204      * @throws OceanusException on error
205      */
206     public static MoneyWiseTransInfoClass fromId(final int id) throws OceanusException {
207         for (MoneyWiseTransInfoClass myClass : values()) {
208             if (myClass.getClassId() == id) {
209                 return myClass;
210             }
211         }
212         throw new MoneyWiseDataException("Invalid ClassId for " + MoneyWiseStaticDataType.TRANSINFOTYPE.toString() + ":" + id);
213     }
214 
215     /**
216      * Obtain maximum length for infoType.
217      *
218      * @return the maximum length
219      */
220     public int getMaximumLength() {
221         switch (this) {
222             case REFERENCE:
223                 return MoneyWiseTransInfoType.DATA_LEN;
224             case COMMENTS:
225                 return MoneyWiseTransInfoType.COMMENT_LEN;
226             default:
227                 return 0;
228         }
229     }
230 
231     @Override
232     public String getId() {
233         return toString();
234     }
235 }