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.MoneyWiseBasicResource;
20  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseCash;
21  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDataSet;
22  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticDataType;
23  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
25  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
26  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetEncrypted;
27  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetReader;
28  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetWriter;
29  
30  /**
31   * SheetDataItem extension for Cash.
32   *
33   * @author Tony Washer
34   */
35  public final class MoneyWiseSheetCash
36          extends PrometheusSheetEncrypted<MoneyWiseCash> {
37      /**
38       * NamedArea for Cash.
39       */
40      private static final String AREA_CASH = MoneyWiseCash.LIST_NAME;
41  
42      /**
43       * Name column.
44       */
45      private static final int COL_NAME = COL_KEYSETID + 1;
46  
47      /**
48       * Category column.
49       */
50      private static final int COL_CATEGORY = COL_NAME + 1;
51  
52      /**
53       * Description column.
54       */
55      private static final int COL_DESC = COL_CATEGORY + 1;
56  
57      /**
58       * Currency column.
59       */
60      private static final int COL_CURRENCY = COL_DESC + 1;
61  
62      /**
63       * Closed column.
64       */
65      private static final int COL_CLOSED = COL_CURRENCY + 1;
66  
67      /**
68       * Constructor for loading a spreadsheet.
69       *
70       * @param pReader the spreadsheet reader
71       */
72      MoneyWiseSheetCash(final PrometheusSheetReader pReader) {
73          /* Call super constructor */
74          super(pReader, AREA_CASH);
75  
76          /* Access the Cash list */
77          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pReader.getData();
78          setDataList(myData.getCash());
79      }
80  
81      /**
82       * Constructor for creating a spreadsheet.
83       *
84       * @param pWriter the spreadsheet writer
85       */
86      MoneyWiseSheetCash(final PrometheusSheetWriter pWriter) {
87          /* Call super constructor */
88          super(pWriter, AREA_CASH);
89  
90          /* Access the Cash list */
91          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pWriter.getData();
92          setDataList(myData.getCash());
93      }
94  
95      @Override
96      protected PrometheusDataValues loadSecureValues() throws OceanusException {
97          /* Build data values */
98          final PrometheusDataValues myValues = getRowValues(MoneyWiseCash.OBJECT_NAME);
99          myValues.addValue(MoneyWiseBasicResource.CATEGORY_NAME, loadInteger(COL_CATEGORY));
100         myValues.addValue(MoneyWiseStaticDataType.CURRENCY, loadInteger(COL_CURRENCY));
101         myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, loadBytes(COL_NAME));
102         myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_DESC, loadBytes(COL_DESC));
103         myValues.addValue(MoneyWiseBasicResource.ASSET_CLOSED, loadBoolean(COL_CLOSED));
104 
105         /* Return the values */
106         return myValues;
107     }
108 
109     @Override
110     protected void insertSecureItem(final MoneyWiseCash pItem) throws OceanusException {
111         /* Set the fields */
112         super.insertSecureItem(pItem);
113         writeInteger(COL_CATEGORY, pItem.getCategoryId());
114         writeInteger(COL_CURRENCY, pItem.getAssetCurrencyId());
115         writeBytes(COL_NAME, pItem.getNameBytes());
116         writeBytes(COL_DESC, pItem.getDescBytes());
117         writeBoolean(COL_CLOSED, pItem.isClosed());
118     }
119 
120     @Override
121     protected int getLastColumn() {
122         /* Return the last column */
123         return COL_CLOSED;
124     }
125 }