private static PriceIndexCalculationMethod parseInflationMethod(Optional<String> strOpt, Currency currency) { if (!strOpt.isPresent()) { if (Currency.JPY.equals(currency)) { return PriceIndexCalculationMethod.INTERPOLATED_JAPAN; } else if (Currency.USD.equals(currency)) { return PriceIndexCalculationMethod.INTERPOLATED; } return PriceIndexCalculationMethod.MONTHLY; } return PriceIndexCalculationMethod.of(strOpt.get()); }
@Test(dataProvider = "name") public void test_toString(PriceIndexCalculationMethod convention, String name) { assertEquals(convention.toString(), name); }
private RateComputation createRateComputation(SchedulePeriod period, int scheduleIndex) { // handle where index value at start date is known LocalDate endDate = period.getEndDate(); if (firstIndexValue != null && scheduleIndex == 0) { return createRateComputation(endDate); } YearMonth referenceStartMonth = YearMonth.from(period.getStartDate().minus(lag)); YearMonth referenceEndMonth = YearMonth.from(endDate.minus(lag)); if (indexCalculationMethod.equals(PriceIndexCalculationMethod.INTERPOLATED)) { // interpolate between data from two different months double weight = 1d - (endDate.getDayOfMonth() - 1d) / endDate.lengthOfMonth(); return InflationInterpolatedRateComputation.of(index, referenceStartMonth, referenceEndMonth, weight); } else if (indexCalculationMethod.equals(PriceIndexCalculationMethod.MONTHLY)) { // no interpolation return InflationMonthlyRateComputation.of(index, referenceStartMonth, referenceEndMonth); } else { throw new IllegalArgumentException( "PriceIndexCalculationMethod " + indexCalculationMethod.toString() + " is not supported"); } }
if (indexCalculationMethod.equals(PriceIndexCalculationMethod.INTERPOLATED)) { } else if (indexCalculationMethod.equals(PriceIndexCalculationMethod.MONTHLY)) { } else if (indexCalculationMethod.equals(PriceIndexCalculationMethod.INTERPOLATED_JAPAN)) { } else { throw new IllegalArgumentException( "PriceIndexCalculationMethod " + indexCalculationMethod.toString() + " is not supported");
@Test(dataProvider = "name") public void test_of_lookup(PriceIndexCalculationMethod convention, String name) { assertEquals(PriceIndexCalculationMethod.of(name), convention); }
public void test_of_lookup_null() { assertThrows(() -> PriceIndexCalculationMethod.of(null), IllegalArgumentException.class); }
public void test_of_lookup_notFound() { assertThrows(() -> PriceIndexCalculationMethod.of("Rubbish"), IllegalArgumentException.class); }