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.atlas.data.analysis.base;
18  
19  import io.github.tonywasher.joceanus.oceanus.date.OceanusDate;
20  import io.github.tonywasher.joceanus.oceanus.decimal.OceanusRate;
21  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicDataType;
22  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDataSet;
23  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDeposit;
24  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDepositRate;
25  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDepositRate.MoneyWiseDepositRateList;
26  import io.github.tonywasher.joceanus.prometheus.views.PrometheusEditSet;
27  
28  import java.util.ArrayList;
29  import java.util.HashMap;
30  import java.util.ListIterator;
31  import java.util.Map;
32  
33  /**
34   * New format of DepositRate.
35   */
36  public class MoneyWiseNewDepositRate {
37      /**
38       * The date.
39       */
40      private final OceanusDate theDate;
41  
42      /**
43       * The Deposit.
44       */
45      private final MoneyWiseDeposit theDeposit;
46  
47      /**
48       * The RAte.
49       */
50      private final OceanusRate theRate;
51  
52      /**
53       * Constructor.
54       *
55       * @param pDate    the date
56       * @param pDeposit the deposit
57       * @param pRate    the rate
58       */
59      MoneyWiseNewDepositRate(final OceanusDate pDate,
60                              final MoneyWiseDeposit pDeposit,
61                              final OceanusRate pRate) {
62          theDate = pDate;
63          theDeposit = pDeposit;
64          theRate = pRate;
65      }
66  
67      /**
68       * Obtain the date.
69       *
70       * @return the date
71       */
72      public OceanusDate getDate() {
73          return theDate;
74      }
75  
76      /**
77       * Obtain the deposit.
78       *
79       * @return the deposit
80       */
81      public MoneyWiseDeposit getDeposit() {
82          return theDeposit;
83      }
84  
85      /**
86       * Obtain the rate.
87       *
88       * @return the rate
89       */
90      public OceanusRate getRate() {
91          return theRate;
92      }
93  
94      /**
95       * NewRateList.
96       */
97      public static class MoneyWiseNewDepositRateList
98              extends ArrayList<MoneyWiseNewDepositRate> {
99          /**
100          * Constructor.
101          *
102          * @param pEditSet the editSet
103          */
104         public MoneyWiseNewDepositRateList(final PrometheusEditSet pEditSet) {
105             /* Create the map */
106             final Map<MoneyWiseDeposit, OceanusDate> myPending = new HashMap<>();
107 
108             /* Determine the starting date */
109             final OceanusDate myStart = ((MoneyWiseDataSet) pEditSet.getDataSet()).getDateRange().getStart();
110 
111             /* Loop through the depositRates */
112             final MoneyWiseDepositRateList mySource = pEditSet.getDataList(MoneyWiseBasicDataType.DEPOSITRATE, MoneyWiseDepositRateList.class);
113             final ListIterator<MoneyWiseDepositRate> myIterator = mySource.listIterator(mySource.size());
114             while (myIterator.hasPrevious()) {
115                 /* Access pending date */
116                 final MoneyWiseDepositRate myRate = myIterator.previous();
117                 final MoneyWiseDeposit myDeposit = myRate.getDeposit();
118                 OceanusDate myDate = myPending.get(myDeposit);
119                 if (myDate == null) {
120                     myDate = myStart;
121                 }
122 
123                 /* Add new element */
124                 add(new MoneyWiseNewDepositRate(myDate, myDeposit, myRate.getRate()));
125 
126                 /* Store the pending date */
127                 myPending.put(myDeposit, myRate.getEndDate());
128             }
129         }
130     }
131 }