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.MetisDataResource;
21  import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
22  import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseDataException;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataItem;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet;
25  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
26  import io.github.tonywasher.joceanus.prometheus.data.PrometheusStaticDataClass;
27  import io.github.tonywasher.joceanus.prometheus.data.PrometheusStaticDataItem;
28  
29  /**
30   * TaxBasis data type.
31   *
32   * @author Tony Washer
33   */
34  public class MoneyWiseTaxBasis
35          extends PrometheusStaticDataItem {
36      /**
37       * Object name.
38       */
39      public static final String OBJECT_NAME = MoneyWiseStaticDataType.TAXBASIS.getItemName();
40  
41      /**
42       * List name.
43       */
44      public static final String LIST_NAME = MoneyWiseStaticDataType.TAXBASIS.getListName();
45  
46      /**
47       * Report fields.
48       */
49      private static final MetisFieldSet<MoneyWiseTaxBasis> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseTaxBasis.class);
50  
51      /**
52       * Copy Constructor.
53       *
54       * @param pList     The list to associate the Tax Basis with
55       * @param pTaxBasis The Tax Basis to copy
56       */
57      protected MoneyWiseTaxBasis(final MoneyWiseTaxBasisList pList,
58                                  final MoneyWiseTaxBasis pTaxBasis) {
59          super(pList, pTaxBasis);
60      }
61  
62      /**
63       * Basic Constructor.
64       *
65       * @param pList The list to associate the Tax Basis with
66       * @param pName Name of Tax Basis
67       * @throws OceanusException on error
68       */
69      private MoneyWiseTaxBasis(final MoneyWiseTaxBasisList pList,
70                                final String pName) throws OceanusException {
71          super(pList, pName);
72      }
73  
74      /**
75       * Basic constructor.
76       *
77       * @param pList  The list to associate the Tax Basis with
78       * @param pClass Class of Tax Basis
79       * @throws OceanusException on error
80       */
81      private MoneyWiseTaxBasis(final MoneyWiseTaxBasisList pList,
82                                final MoneyWiseTaxClass pClass) throws OceanusException {
83          super(pList, pClass);
84      }
85  
86      /**
87       * Values constructor.
88       *
89       * @param pList   The list to associate the item with
90       * @param pValues the values
91       * @throws OceanusException on error
92       */
93      private MoneyWiseTaxBasis(final MoneyWiseTaxBasisList pList,
94                                final PrometheusDataValues pValues) throws OceanusException {
95          super(pList, pValues);
96      }
97  
98      @Override
99      public MetisFieldSetDef getDataFieldSet() {
100         return FIELD_DEFS;
101     }
102 
103     /**
104      * Return the Tax class of the Tax Basis.
105      *
106      * @return the class
107      */
108     public MoneyWiseTaxClass getTaxClass() {
109         return (MoneyWiseTaxClass) super.getStaticClass();
110     }
111 
112     @Override
113     public MoneyWiseTaxBasis getBase() {
114         return (MoneyWiseTaxBasis) super.getBase();
115     }
116 
117     @Override
118     public MoneyWiseTaxBasisList getList() {
119         return (MoneyWiseTaxBasisList) super.getList();
120     }
121 
122     @Override
123     public boolean isActive() {
124         return true;
125     }
126 
127     /**
128      * Determine whether we this is the tax paid category.
129      *
130      * @return <code>true</code> if we should add tax credits to the total, <code>false</code>
131      * otherwise.
132      */
133     public boolean isTaxPaid() {
134         return MoneyWiseTaxClass.TAXPAID.equals(getTaxClass());
135     }
136 
137     /**
138      * Represents a list of {@link MoneyWiseTaxBasis} objects.
139      */
140     public static class MoneyWiseTaxBasisList
141             extends PrometheusStaticList<MoneyWiseTaxBasis> {
142         /**
143          * Report fields.
144          */
145         private static final MetisFieldSet<MoneyWiseTaxBasisList> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseTaxBasisList.class);
146 
147         /**
148          * Construct an empty CORE tax bucket list.
149          *
150          * @param pData the DataSet for the list
151          */
152         public MoneyWiseTaxBasisList(final PrometheusDataSet pData) {
153             super(MoneyWiseTaxBasis.class, pData, MoneyWiseStaticDataType.TAXBASIS, PrometheusListStyle.CORE);
154         }
155 
156         /**
157          * Constructor for a cloned List.
158          *
159          * @param pSource the source List
160          */
161         private MoneyWiseTaxBasisList(final MoneyWiseTaxBasisList pSource) {
162             super(pSource);
163         }
164 
165         @Override
166         public MetisFieldSet<MoneyWiseTaxBasisList> getDataFieldSet() {
167             return FIELD_DEFS;
168         }
169 
170         @Override
171         public String listName() {
172             return LIST_NAME;
173         }
174 
175         @Override
176         public MetisFieldSetDef getItemFields() {
177             return MoneyWiseTaxBasis.FIELD_DEFS;
178         }
179 
180         @Override
181         protected Class<MoneyWiseTaxClass> getEnumClass() {
182             return MoneyWiseTaxClass.class;
183         }
184 
185         @Override
186         protected MoneyWiseTaxBasisList getEmptyList(final PrometheusListStyle pStyle) {
187             final MoneyWiseTaxBasisList myList = new MoneyWiseTaxBasisList(this);
188             myList.setStyle(pStyle);
189             return myList;
190         }
191 
192         /**
193          * Add a new item to the list.
194          *
195          * @param pItem item to be added
196          * @return the newly added item
197          */
198         @Override
199         public MoneyWiseTaxBasis addCopyItem(final PrometheusDataItem pItem) {
200             /* Can only clone a TaxBasis */
201             if (!(pItem instanceof MoneyWiseTaxBasis)) {
202                 throw new UnsupportedOperationException();
203             }
204 
205             final MoneyWiseTaxBasis myBasis = new MoneyWiseTaxBasis(this, (MoneyWiseTaxBasis) pItem);
206             add(myBasis);
207             return myBasis;
208         }
209 
210         /**
211          * Create a new empty element in the edit list (null-operation).
212          *
213          * @return the newly added item
214          */
215         @Override
216         public MoneyWiseTaxBasis addNewItem() {
217             throw new UnsupportedOperationException();
218         }
219 
220         /**
221          * Obtain the type of the item.
222          *
223          * @return the type of the item
224          */
225         public String itemType() {
226             return LIST_NAME;
227         }
228 
229         /**
230          * Add a TaxBasis.
231          *
232          * @param pTaxBasis the Name of the tax basis
233          * @return the new basis
234          * @throws OceanusException on error
235          */
236         public MoneyWiseTaxBasis addBasicItem(final String pTaxBasis) throws OceanusException {
237             /* Create a new Tax Basis */
238             final MoneyWiseTaxBasis myBasis = new MoneyWiseTaxBasis(this, pTaxBasis);
239 
240             /* Check that this TaxBasisId has not been previously added */
241             if (!isIdUnique(myBasis.getIndexedId())) {
242                 myBasis.addError(ERROR_DUPLICATE, MetisDataResource.DATA_ID);
243                 throw new MoneyWiseDataException(myBasis, ERROR_VALIDATION);
244             }
245 
246             /* Add the Tax Basis to the list */
247             add(myBasis);
248             return myBasis;
249         }
250 
251         @Override
252         public MoneyWiseTaxBasis addValuesItem(final PrometheusDataValues pValues) throws OceanusException {
253             /* Create the basis */
254             final MoneyWiseTaxBasis myBasis = new MoneyWiseTaxBasis(this, pValues);
255 
256             /* Check that this BasisId has not been previously added */
257             if (!isIdUnique(myBasis.getIndexedId())) {
258                 myBasis.addError(ERROR_DUPLICATE, MetisDataResource.DATA_ID);
259                 throw new MoneyWiseDataException(myBasis, ERROR_VALIDATION);
260             }
261 
262             /* Add to the list */
263             add(myBasis);
264 
265             /* Return it */
266             return myBasis;
267         }
268 
269         @Override
270         protected MoneyWiseTaxBasis newItem(final PrometheusStaticDataClass pClass) throws OceanusException {
271             /* Create the basis */
272             final MoneyWiseTaxBasis myBasis = new MoneyWiseTaxBasis(this, (MoneyWiseTaxClass) pClass);
273 
274             /* Check that this BasisId has not been previously added */
275             if (!isIdUnique(myBasis.getIndexedId())) {
276                 myBasis.addError(ERROR_DUPLICATE, MetisDataResource.DATA_ID);
277                 throw new MoneyWiseDataException(myBasis, ERROR_VALIDATION);
278             }
279 
280             /* Add to the list */
281             add(myBasis);
282 
283             /* Return it */
284             return myBasis;
285         }
286     }
287 }