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.sheets;
18  
19  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicDataType;
20  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicResource;
21  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDataSet;
22  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDepositRate;
23  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
25  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetEncrypted;
26  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetReader;
27  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetWriter;
28  
29  /**
30   * SheetDataItem extension for DepositRate.
31   *
32   * @author Tony Washer
33   */
34  public final class MoneyWiseSheetDepositRate
35          extends PrometheusSheetEncrypted<MoneyWiseDepositRate> {
36      /**
37       * NamedArea for Rates.
38       */
39      private static final String AREA_RATES = MoneyWiseDepositRate.LIST_NAME;
40  
41      /**
42       * Deposit column.
43       */
44      private static final int COL_DEPOSIT = COL_KEYSETID + 1;
45  
46      /**
47       * Rate column.
48       */
49      private static final int COL_RATE = COL_DEPOSIT + 1;
50  
51      /**
52       * Bonus column.
53       */
54      private static final int COL_BONUS = COL_RATE + 1;
55  
56      /**
57       * EndDate column.
58       */
59      private static final int COL_ENDDATE = COL_BONUS + 1;
60  
61      /**
62       * Constructor for loading a spreadsheet.
63       *
64       * @param pReader the spreadsheet reader
65       */
66      MoneyWiseSheetDepositRate(final PrometheusSheetReader pReader) {
67          /* Call super constructor */
68          super(pReader, AREA_RATES);
69  
70          /* Access the Rates list */
71          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pReader.getData();
72          setDataList(myData.getDepositRates());
73      }
74  
75      /**
76       * Constructor for creating a spreadsheet.
77       *
78       * @param pWriter the spreadsheet writer
79       */
80      MoneyWiseSheetDepositRate(final PrometheusSheetWriter pWriter) {
81          /* Call super constructor */
82          super(pWriter, AREA_RATES);
83  
84          /* Access the Rates list */
85          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pWriter.getData();
86          setDataList(myData.getDepositRates());
87      }
88  
89      @Override
90      protected PrometheusDataValues loadSecureValues() throws OceanusException {
91          /* Build data values */
92          final PrometheusDataValues myValues = getRowValues(MoneyWiseDepositRate.OBJECT_NAME);
93          myValues.addValue(MoneyWiseBasicDataType.DEPOSIT, loadInteger(COL_DEPOSIT));
94          myValues.addValue(MoneyWiseBasicResource.MONEYWISEDATA_FIELD_RATE, loadBytes(COL_RATE));
95          myValues.addValue(MoneyWiseBasicResource.DEPOSITRATE_BONUS, loadBytes(COL_BONUS));
96          myValues.addValue(MoneyWiseBasicResource.DEPOSITRATE_ENDDATE, loadDate(COL_ENDDATE));
97  
98          /* Return the values */
99          return myValues;
100     }
101 
102     @Override
103     protected void insertSecureItem(final MoneyWiseDepositRate pItem) throws OceanusException {
104         /* Set the fields */
105         super.insertSecureItem(pItem);
106         writeInteger(COL_DEPOSIT, pItem.getDepositId());
107         writeBytes(COL_RATE, pItem.getRateBytes());
108         writeBytes(COL_BONUS, pItem.getBonusBytes());
109         writeDate(COL_ENDDATE, pItem.getEndDate());
110     }
111 
112     @Override
113     protected int getLastColumn() {
114         /* Return the last column */
115         return COL_ENDDATE;
116     }
117 }