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