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.data.validate;
18  
19  import io.github.tonywasher.joceanus.metis.list.MetisListKey;
20  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicDataType;
21  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticDataType;
22  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet.PrometheusCryptographyDataType;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValidator;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValidator.PrometheusDataValidatorFactory;
25  import io.github.tonywasher.joceanus.prometheus.validate.PrometheusValidateBasic;
26  import io.github.tonywasher.joceanus.prometheus.validate.PrometheusValidateInfo;
27  import io.github.tonywasher.joceanus.prometheus.validate.PrometheusValidateStatic;
28  
29  /**
30   * Validator factory.
31   */
32  public class MoneyWiseValidatorFactory
33          implements PrometheusDataValidatorFactory {
34      /**
35       * Are we using new Validation?
36       */
37      private final boolean newValidation;
38  
39      /**
40       * Constructor.
41       */
42      public MoneyWiseValidatorFactory() {
43          this(false);
44      }
45  
46      /**
47       * Constructor.
48       *
49       * @param pNewValidation true/false
50       */
51      public MoneyWiseValidatorFactory(final boolean pNewValidation) {
52          newValidation = pNewValidation;
53      }
54  
55      @Override
56      public PrometheusDataValidator newValidator(final MetisListKey pItemType) {
57          if (pItemType instanceof PrometheusCryptographyDataType) {
58              return new PrometheusValidateBasic();
59          } else if (MoneyWiseStaticDataType.CURRENCY.equals(pItemType)) {
60              return new MoneyWiseValidateCurrency();
61          } else if (pItemType instanceof MoneyWiseStaticDataType) {
62              return new PrometheusValidateStatic();
63          } else if (pItemType instanceof MoneyWiseBasicDataType myType) {
64              switch (myType) {
65                  case TRANSTAG:
66                      return new MoneyWiseValidateTransTag();
67                  case REGION:
68                      return new MoneyWiseValidateRegion();
69                  case DEPOSITCATEGORY:
70                      return new MoneyWiseValidateDepositCategory();
71                  case CASHCATEGORY:
72                      return new MoneyWiseValidateCashCategory();
73                  case LOANCATEGORY:
74                      return new MoneyWiseValidateLoanCategory();
75                  case TRANSCATEGORY:
76                      return new MoneyWiseValidateTransCategory();
77                  case EXCHANGERATE:
78                      return new MoneyWiseValidateXchangeRate();
79                  case PAYEE:
80                      return new MoneyWiseValidatePayee();
81                  case SECURITY:
82                      return new MoneyWiseValidateSecurity();
83                  case SECURITYPRICE:
84                      return new MoneyWiseValidateSecurityPrice();
85                  case DEPOSIT:
86                      return new MoneyWiseValidateDeposit();
87                  case DEPOSITRATE:
88                      return new MoneyWiseValidateDepositRate();
89                  case CASH:
90                      return new MoneyWiseValidateCash();
91                  case LOAN:
92                      return new MoneyWiseValidateLoan();
93                  case PORTFOLIO:
94                      return new MoneyWiseValidatePortfolio();
95                  case TRANSACTION:
96                      return new MoneyWiseValidateTransaction(newValidation);
97                  case PAYEEINFO:
98                  case DEPOSITINFO:
99                  case SECURITYINFO:
100                 case CASHINFO:
101                 case LOANINFO:
102                 case PORTFOLIOINFO:
103                 case TRANSACTIONINFO:
104                     return new PrometheusValidateInfo();
105                 default:
106                     break;
107             }
108         }
109 
110         /* Throw error */
111         throw new IllegalArgumentException("Unexpected itemType " + pItemType);
112     }
113 }