/** * Obtains an instance from the specified unique name. * * @param uniqueName the unique name * @return the addition convention * @throws IllegalArgumentException if the name is not known */ @FromString public static PeriodAdditionConvention of(String uniqueName) { return extendedEnum().lookup(uniqueName); }
@Test(dataProvider = "name") public void test_name(PeriodAdditionConvention convention, String name) { assertEquals(convention.getName(), name); }
@ImmutableValidator private void validate() { if (additionConvention.isMonthBased() && period.getDays() != 0) { throw new IllegalArgumentException("Period must not contain days when addition convention is month-based"); } }
@Test(dataProvider = "convention") public void test_convention(PeriodAdditionConvention convention, LocalDate input, int months, LocalDate expected) { assertEquals(convention.adjust(input, Period.ofMonths(months), HolidayCalendars.SAT_SUN), expected); }
@Test(dataProvider = "name") public void test_of_lookup(PeriodAdditionConvention convention, String name) { assertEquals(PeriodAdditionConvention.of(name), convention); }
/** * Resolves this adjustment using the specified reference data, returning an adjuster. * <p> * This returns a {@link DateAdjuster} that performs the same calculation as this adjustment. * It binds the holiday calendar, looked up from the reference data, into the result. * As such, there is no need to pass the reference data in again. * * @param refData the reference data, used to find the holiday calendar * @return the adjuster, bound to a specific holiday calendar */ @Override public DateAdjuster resolve(ReferenceData refData) { HolidayCalendar holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); return date -> bda.adjust(additionConvention.adjust(date, period, holCal), holCal); }
public void test_of_lookup_null() { assertThrowsIllegalArg(() -> PeriodAdditionConvention.of(null)); }
@Test(dataProvider = "types") public void test_null(PeriodAdditionConvention type) { assertThrowsIllegalArg(() -> type.adjust(null, Period.ofMonths(3), HolidayCalendars.NO_HOLIDAYS)); assertThrowsIllegalArg(() -> type.adjust(date(2014, 7, 11), null, HolidayCalendars.NO_HOLIDAYS)); assertThrowsIllegalArg(() -> type.adjust(date(2014, 7, 11), Period.ofMonths(3), null)); assertThrowsIllegalArg(() -> type.adjust(null, null, null)); }
@Test(dataProvider = "name") public void test_extendedEnum(PeriodAdditionConvention convention, String name) { ImmutableMap<String, PeriodAdditionConvention> map = PeriodAdditionConvention.extendedEnum().lookupAll(); assertEquals(map.get(name), convention); }
public void test_of_lookup_notFound() { assertThrowsIllegalArg(() -> PeriodAdditionConvention.of("Rubbish")); }
@ImmutableValidator private void validate() { if (additionConvention.isMonthBased() && tenor.isMonthBased() == false) { throw new IllegalArgumentException("Tenor must not contain days when addition convention is month-based"); } }
/** * Adjusts the date, adding the period and then applying the business day adjustment. * <p> * The calculation is performed in two steps. * <p> * Step one, use {@link PeriodAdditionConvention#adjust(LocalDate, Period, HolidayCalendar)} to add the period. * <p> * Step two, use {@link BusinessDayAdjustment#adjust(LocalDate, ReferenceData)} to adjust the result of step one. * * @param date the date to adjust * @param refData the reference data, used to find the holiday calendar * @return the adjusted date */ public LocalDate adjust(LocalDate date, ReferenceData refData) { HolidayCalendar holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); return bda.adjust(additionConvention.adjust(date, period, holCal), holCal); }
PeriodAdditionConvention.extendedEnum().find(row.getField(TENOR_CONVENTION_FIELD)) .orElse(PeriodAdditionConventions.NONE); BusinessDayConvention tenorBusinessConvention =
/** * Resolves this adjustment using the specified reference data, returning an adjuster. * <p> * This returns a {@link DateAdjuster} that performs the same calculation as this adjustment. * It binds the holiday calendar, looked up from the reference data, into the result. * As such, there is no need to pass the reference data in again. * * @param refData the reference data, used to find the holiday calendar * @return the adjuster, bound to a specific holiday calendar */ @Override public DateAdjuster resolve(ReferenceData refData) { HolidayCalendar holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); Period period = tenor.getPeriod(); return date -> bda.adjust(additionConvention.adjust(date, period, holCal), holCal); }
/** * Adjusts the date, adding the tenor and then applying the business day adjustment. * <p> * The calculation is performed in two steps. * <p> * Step one, use {@link PeriodAdditionConvention#adjust(LocalDate, Period, HolidayCalendar)} to add the period. * <p> * Step two, use {@link BusinessDayAdjustment#adjust(LocalDate, ReferenceData)} to adjust the result of step one. * * @param date the date to adjust * @param refData the reference data, used to find the holiday calendar * @return the adjusted date */ public LocalDate adjust(LocalDate date, ReferenceData refData) { HolidayCalendar holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); return bda.adjust(additionConvention.adjust(date, tenor.getPeriod(), holCal), holCal); }