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.basic;
18  
19  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20  import io.github.tonywasher.joceanus.metis.data.MetisDataFieldValue;
21  import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataFieldId;
22  import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
23  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDepositInfo.MoneyWiseDepositInfoList;
24  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseAccountInfoClass;
25  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseAccountInfoType.MoneyWiseAccountInfoTypeList;
26  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataInfoClass;
27  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataInfoSet;
28  import io.github.tonywasher.joceanus.prometheus.views.PrometheusEditSet;
29  
30  import java.util.Arrays;
31  import java.util.Iterator;
32  import java.util.Map;
33  
34  /**
35   * DepositInfoSet class.
36   *
37   * @author Tony Washer
38   */
39  public class MoneyWiseDepositInfoSet
40          extends PrometheusDataInfoSet<MoneyWiseDepositInfo> {
41      /**
42       * Report fields.
43       */
44      private static final MetisFieldSet<MoneyWiseDepositInfoSet> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseDepositInfoSet.class);
45  
46      /**
47       * FieldSet map.
48       */
49      private static final Map<MetisDataFieldId, MoneyWiseAccountInfoClass> FIELDSET_MAP = FIELD_DEFS.buildFieldMap(MoneyWiseAccountInfoClass.class, MoneyWiseDepositInfoSet::getFieldValue);
50  
51      /**
52       * Reverse FieldSet map.
53       */
54      private static final Map<MoneyWiseAccountInfoClass, MetisDataFieldId> REVERSE_FIELDMAP = MetisFieldSet.reverseFieldMap(FIELDSET_MAP, MoneyWiseAccountInfoClass.class);
55  
56      /**
57       * Opening Balance Currency Error Text.
58       */
59      public static final String ERROR_CURRENCY = MoneyWiseBasicResource.MONEYWISEDATA_ERROR_CURRENCY.getValue();
60  
61      /**
62       * Constructor.
63       *
64       * @param pOwner    the Owner to which this Set belongs
65       * @param pTypeList the infoTypeList for the set
66       * @param pInfoList the InfoList for the set
67       */
68      protected MoneyWiseDepositInfoSet(final MoneyWiseDeposit pOwner,
69                                        final MoneyWiseAccountInfoTypeList pTypeList,
70                                        final MoneyWiseDepositInfoList pInfoList) {
71          /* Store the Owner and Info List */
72          super(pOwner, pTypeList, pInfoList);
73      }
74  
75      @Override
76      public MetisFieldSetDef getDataFieldSet() {
77          return FIELD_DEFS;
78      }
79  
80      @Override
81      public MoneyWiseDeposit getOwner() {
82          return (MoneyWiseDeposit) super.getOwner();
83      }
84  
85      /**
86       * Obtain fieldValue for infoSet.
87       *
88       * @param pFieldId the fieldId
89       * @return the value
90       */
91      public Object getFieldValue(final MetisDataFieldId pFieldId) {
92          /* Handle InfoSet fields */
93          final MoneyWiseAccountInfoClass myClass = getClassForField(pFieldId);
94          if (myClass != null) {
95              return getInfoSetValue(myClass);
96          }
97  
98          /* Pass onwards */
99          return null;
100     }
101 
102     /**
103      * Obtain the class of the field if it is an infoSet field.
104      *
105      * @param pField the field
106      * @return the class
107      */
108     public static MoneyWiseAccountInfoClass getClassForField(final MetisDataFieldId pField) {
109         /* Look up field in map */
110         return FIELDSET_MAP.get(pField);
111     }
112 
113     /**
114      * Obtain the field for the infoSet class.
115      *
116      * @param pClass the class
117      * @return the field
118      */
119     public static MetisDataFieldId getFieldForClass(final MoneyWiseAccountInfoClass pClass) {
120         /* Look up field in map */
121         return REVERSE_FIELDMAP.get(pClass);
122     }
123 
124     @Override
125     public MetisDataFieldId getFieldForClass(final PrometheusDataInfoClass pClass) {
126         return getFieldForClass((MoneyWiseAccountInfoClass) pClass);
127     }
128 
129     /**
130      * Get an infoSet value.
131      *
132      * @param pInfoClass the class of info to get
133      * @return the value to set
134      */
135     private Object getInfoSetValue(final MoneyWiseAccountInfoClass pInfoClass) {
136         /* Return the value */
137         final Object myValue = getField(pInfoClass);
138         return myValue != null
139                 ? myValue
140                 : MetisDataFieldValue.SKIP;
141     }
142 
143     @Override
144     public Iterator<PrometheusDataInfoClass> classIterator() {
145         final PrometheusDataInfoClass[] myValues = MoneyWiseAccountInfoClass.values();
146         return Arrays.stream(myValues).iterator();
147     }
148 
149     /**
150      * Clone the dataInfoSet.
151      *
152      * @param pSource the InfoSet to clone
153      */
154     protected void cloneDataInfoSet(final MoneyWiseDepositInfoSet pSource) {
155         /* Clone the dataInfoSet */
156         cloneTheDataInfoSet(pSource);
157     }
158 
159     /**
160      * Resolve editSetLinks.
161      *
162      * @param pEditSet the editSet
163      * @throws OceanusException on error
164      */
165     void resolveEditSetLinks(final PrometheusEditSet pEditSet) throws OceanusException {
166         /* Loop through the items */
167         for (MoneyWiseDepositInfo myInfo : this) {
168             myInfo.resolveEditSetLinks(pEditSet);
169         }
170     }
171 }