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.tax;
18  
19  import io.github.tonywasher.joceanus.oceanus.date.OceanusDate;
20  import io.github.tonywasher.joceanus.oceanus.date.OceanusDateRange;
21  import io.github.tonywasher.joceanus.oceanus.date.OceanusFiscalYear;
22  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseTax.MoneyWiseTaxFactory;
23  
24  /**
25   * Tax Year cache.
26   */
27  public abstract class MoneyWiseTaxYearCache
28          implements MoneyWiseTaxFactory {
29      /**
30       * The Fiscal Year.
31       */
32      private final OceanusFiscalYear theFiscalYear;
33  
34      /**
35       * Constructor.
36       *
37       * @param pYear the fiscal year
38       */
39      protected MoneyWiseTaxYearCache(final OceanusFiscalYear pYear) {
40          theFiscalYear = pYear;
41      }
42  
43      /**
44       * Obtain the taxYear date.
45       *
46       * @param pDate the date
47       * @return the date
48       */
49      protected OceanusDate getTaxYearDate(final OceanusDate pDate) {
50          return theFiscalYear.endOfYear(pDate);
51      }
52  
53      /**
54       * Check whether the range matches a taxYear.
55       *
56       * @param pRange the range
57       * @return true/false
58       */
59      protected boolean checkTaxYearRange(final OceanusDateRange pRange) {
60          /* Check that the range ends of a tax year boundary */
61          final OceanusDate myEnd = pRange.getEnd();
62          if ((myEnd == null)
63                  || !myEnd.equals(getTaxYearDate(myEnd))) {
64              return false;
65          }
66  
67          /* Check that the range starts on the correct taxYear boundary */
68          final OceanusDate myStart = new OceanusDate(myEnd);
69          myStart.adjustYear(-1);
70          myStart.adjustDay(1);
71          return myStart.equals(pRange.getStart());
72      }
73  }