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.MoneyWiseSecurityPrice;
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 SecurityPrice.
31   *
32   * @author Tony Washer
33   */
34  public final class MoneyWiseSheetSecurityPrice
35          extends PrometheusSheetEncrypted<MoneyWiseSecurityPrice> {
36      /**
37       * NamedArea for Prices.
38       */
39      private static final String AREA_PRICES = MoneyWiseSecurityPrice.LIST_NAME;
40  
41      /**
42       * Security column.
43       */
44      private static final int COL_SECURITY = COL_KEYSETID + 1;
45  
46      /**
47       * Date column.
48       */
49      private static final int COL_DATE = COL_SECURITY + 1;
50  
51      /**
52       * Price column.
53       */
54      private static final int COL_PRICE = COL_DATE + 1;
55  
56      /**
57       * Constructor for loading a spreadsheet.
58       *
59       * @param pReader the spreadsheet reader
60       */
61      MoneyWiseSheetSecurityPrice(final PrometheusSheetReader pReader) {
62          /* Call super constructor */
63          super(pReader, AREA_PRICES);
64  
65          /* Access the Prices list */
66          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pReader.getData();
67          setDataList(myData.getSecurityPrices());
68      }
69  
70      /**
71       * Constructor for creating a spreadsheet.
72       *
73       * @param pWriter the spreadsheet writer
74       */
75      MoneyWiseSheetSecurityPrice(final PrometheusSheetWriter pWriter) {
76          /* Call super constructor */
77          super(pWriter, AREA_PRICES);
78  
79          /* Access the Prices list */
80          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pWriter.getData();
81          setDataList(myData.getSecurityPrices());
82      }
83  
84      @Override
85      protected PrometheusDataValues loadSecureValues() throws OceanusException {
86          /* Build data values */
87          final PrometheusDataValues myValues = getRowValues(MoneyWiseSecurityPrice.OBJECT_NAME);
88          myValues.addValue(MoneyWiseBasicDataType.SECURITY, loadInteger(COL_SECURITY));
89          myValues.addValue(MoneyWiseBasicResource.MONEYWISEDATA_FIELD_DATE, loadDate(COL_DATE));
90          myValues.addValue(MoneyWiseBasicResource.MONEYWISEDATA_FIELD_PRICE, loadBytes(COL_PRICE));
91  
92          /* Return the values */
93          return myValues;
94      }
95  
96      @Override
97      protected void insertSecureItem(final MoneyWiseSecurityPrice pItem) throws OceanusException {
98          /* Set the fields */
99          super.insertSecureItem(pItem);
100         writeInteger(COL_SECURITY, pItem.getSecurityId());
101         writeDate(COL_DATE, pItem.getDate());
102         writeBytes(COL_PRICE, pItem.getPriceBytes());
103     }
104 
105     @Override
106     protected int getLastColumn() {
107         /* Return the last column */
108         return COL_PRICE;
109     }
110 }