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