/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(PeriodAdjustment beanToCopy) { this.period = beanToCopy.getPeriod(); this.additionConvention = beanToCopy.getAdditionConvention(); this.adjustment = beanToCopy.getAdjustment(); }
@Override public PeriodAdjustment build() { return new PeriodAdjustment( period, additionConvention, adjustment); }
public void test_of_additionConventionNone() { PeriodAdjustment test = PeriodAdjustment.of(Period.of(1, 2, 3), PAC_NONE, BDA_NONE); assertEquals(test.getPeriod(), Period.of(1, 2, 3)); assertEquals(test.getAdditionConvention(), PAC_NONE); assertEquals(test.getAdjustment(), BDA_NONE); assertEquals(test.toString(), "P1Y2M3D"); }
public void test_ofLastBusinessDay() { PeriodAdjustment test = PeriodAdjustment.ofLastBusinessDay(Period.ofMonths(3), BDA_FOLLOW_SAT_SUN); assertEquals(test.getPeriod(), Period.ofMonths(3)); assertEquals(test.getAdditionConvention(), LAST_BUSINESS_DAY); assertEquals(test.getAdjustment(), BDA_FOLLOW_SAT_SUN); assertEquals(test.toString(), "P3M with LastBusinessDay then apply Following using calendar Sat/Sun"); }
public void test_ofLastDay() { PeriodAdjustment test = PeriodAdjustment.ofLastDay(Period.ofMonths(3), BDA_FOLLOW_SAT_SUN); assertEquals(test.getPeriod(), Period.ofMonths(3)); assertEquals(test.getAdditionConvention(), LAST_DAY); assertEquals(test.getAdjustment(), BDA_FOLLOW_SAT_SUN); assertEquals(test.toString(), "P3M with LastDay then apply Following using calendar Sat/Sun"); }
public void test_beanBuilder() { PeriodAdjustment test = PeriodAdjustment.builder() .period(Period.ofMonths(3)) .additionConvention(LAST_DAY) .adjustment(BDA_FOLLOW_SAT_SUN) .build(); assertEquals(test.getPeriod(), Period.ofMonths(3)); assertEquals(test.getAdditionConvention(), LAST_DAY); assertEquals(test.getAdjustment(), BDA_FOLLOW_SAT_SUN); }
public void test_NONE() { PeriodAdjustment test = PeriodAdjustment.NONE; assertEquals(test.getPeriod(), Period.ZERO); assertEquals(test.getAdjustment(), BDA_NONE); assertEquals(test.toString(), "P0D"); }
@Test(dataProvider = "adjust") public void test_adjust(int months, LocalDate date, LocalDate expected) { PeriodAdjustment test = PeriodAdjustment.of(Period.ofMonths(months), LAST_DAY, BDA_FOLLOW_SAT_SUN); assertEquals(test.adjust(date, REF_DATA), expected); assertEquals(test.resolve(REF_DATA).adjust(date), expected); }
public void test_of_invalid_conventionForPeriod() { Period period = Period.of(1, 2, 3); assertThrowsIllegalArg(() -> PeriodAdjustment.of(period, LAST_DAY, BDA_NONE)); assertThrowsIllegalArg(() -> PeriodAdjustment.of(period, LAST_BUSINESS_DAY, BDA_NONE)); assertThrowsIllegalArg(() -> PeriodAdjustment.ofLastDay(period, BDA_NONE)); assertThrowsIllegalArg(() -> PeriodAdjustment.ofLastBusinessDay(period, BDA_NONE)); }
public void equals() { PeriodAdjustment a = PeriodAdjustment.of(Period.ofMonths(3), LAST_DAY, BDA_FOLLOW_SAT_SUN); PeriodAdjustment b = PeriodAdjustment.of(Period.ofMonths(1), LAST_DAY, BDA_FOLLOW_SAT_SUN); PeriodAdjustment c = PeriodAdjustment.of(Period.ofMonths(3), PAC_NONE, BDA_FOLLOW_SAT_SUN); PeriodAdjustment d = PeriodAdjustment.of(Period.ofMonths(3), LAST_DAY, BDA_NONE); assertEquals(a.equals(b), false); assertEquals(a.equals(c), false); assertEquals(a.equals(d), false); }
public void coverage() { coverImmutableBean(PeriodAdjustment.of(Period.ofMonths(3), LAST_DAY, BDA_FOLLOW_SAT_SUN)); }
public void test_of_additionConventionLastDay() { PeriodAdjustment test = PeriodAdjustment.of(Period.ofMonths(3), LAST_DAY, BDA_FOLLOW_SAT_SUN); assertEquals(test.getPeriod(), Period.ofMonths(3)); assertEquals(test.getAdditionConvention(), LAST_DAY); assertEquals(test.getAdjustment(), BDA_FOLLOW_SAT_SUN); assertEquals(test.toString(), "P3M with LastDay then apply Following using calendar Sat/Sun"); }
public void test_serialization() { assertSerialization(PeriodAdjustment.of(Period.ofMonths(3), LAST_DAY, BDA_FOLLOW_SAT_SUN)); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -991726143: // period return ((PeriodAdjustment) bean).getPeriod(); case 1652975501: // additionConvention return ((PeriodAdjustment) bean).getAdditionConvention(); case 1977085293: // adjustment return ((PeriodAdjustment) bean).getAdjustment(); } return super.propertyGet(bean, propertyName, quiet); }
/** * Obtains an instance that can adjust a date by the specified period. * <p> * When adjusting a date, the specified period is added to the input date. * The business day adjustment will then be used to ensure the result is a valid business day. * * @param period the period to add to the input date * @param additionConvention the convention used to perform the addition * @param adjustment the business day adjustment to apply to the result of the addition * @return the period adjustment */ public static PeriodAdjustment of( Period period, PeriodAdditionConvention additionConvention, BusinessDayAdjustment adjustment) { return new PeriodAdjustment(period, additionConvention, adjustment); }
/** * Obtains an instance that can adjust a date by the specified period using the * last business day of month convention. * <p> * When adjusting a date, the specified period is added to the input date. * The business day adjustment will then be used to ensure the result is a valid business day. * <p> * The period must consist only of months and/or years. * * @param period the period to add to the input date * @param adjustment the business day adjustment to apply to the result of the addition * @return the period adjustment */ public static PeriodAdjustment ofLastBusinessDay(Period period, BusinessDayAdjustment adjustment) { return new PeriodAdjustment(period, PeriodAdditionConventions.LAST_BUSINESS_DAY, adjustment); }
/** * Obtains an instance that can adjust a date by the specified period using the * last day of month convention. * <p> * When adjusting a date, the specified period is added to the input date. * The business day adjustment will then be used to ensure the result is a valid business day. * <p> * The period must consist only of months and/or years. * * @param period the period to add to the input date * @param adjustment the business day adjustment to apply to the result of the addition * @return the period adjustment */ public static PeriodAdjustment ofLastDay(Period period, BusinessDayAdjustment adjustment) { return new PeriodAdjustment(period, PeriodAdditionConventions.LAST_DAY, adjustment); }