ScheduleCalculator { public static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime[] dates, final BusinessDayConvention convention, final Calendar calendar, final boolean eomApply) { final ZonedDateTime[] result = new ZonedDateTime[dates.length]; if (eomApply) { final BusinessDayConvention precedingDBC = new PrecedingBusinessDayConvention(); for (int loopdate = 0; loopdate < dates.length; loopdate++) { result[loopdate] = precedingDBC.adjustDate(calendar, dates[loopdate].with(TemporalAdjusters.lastDayOfMonth())); } return result; } for (int loopdate = 0; loopdate < dates.length; loopdate++) { result[loopdate] = convention.adjustDate(calendar, dates[loopdate]); } return result; } private  ScheduleCalculator(); static ZonedDateTime getAdjustedDate(final ZonedDateTime date, final int shiftDays, final Calendar calendar); static ZonedDateTime[] getAdjustedDate(final ZonedDateTime[] dates, final int shiftDays, final Calendar calendar); static ZonedDateTime getAdjustedDate(final ZonedDateTime date, final Period shiftDays, final Calendar calendar); static LocalDate getAdjustedDate(final LocalDate date, final int shiftDays, final Calendar calendar); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final Period tenor, final BusinessDayConvention convention, final Calendar calendar); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final Period tenor, final BusinessDayConvention convention, final Calendar calendar,
      final boolean endOfMonthRule); static ZonedDateTime getAdjustedDate(
      final ZonedDateTime startDate,
      final Period period,
      final BusinessDayConvention convention,
      final Calendar calendar,
      final RollDateAdjuster rollDateAdjuster); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final Tenor tenor, final BusinessDayConvention convention, final Calendar calendar,
      final boolean endOfMonthRule); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final Period tenor, final GeneratorDeposit generator); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final Period tenor, final IborIndex index, final Calendar calendar); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final IborIndex index, final Calendar calendar); static ZonedDateTime[] getAdjustedDate(final ZonedDateTime[] startDates, final IborIndex index, final Calendar calendar); static ZonedDateTime[] getUnadjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period tenorPeriod, final StubType stub); static ZonedDateTime[] getUnadjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period tenorPeriod, final boolean stubShort,
      final boolean fromEnd); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime[] dates, final BusinessDayConvention convention, final Calendar calendar,
      final boolean eomApply); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime[] dates, final BusinessDayConvention convention, final Calendar calendar,
      final boolean eomApply, final RollDateAdjuster adjuster); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period schedulePeriod, final boolean stubShort,
      final boolean fromEnd, final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period schedulePeriod, final boolean stubShort,
      final boolean fromEnd, final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule, final RollDateAdjuster adjuster); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period schedulePeriod, final StubType stub,
      final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period schedulePeriod, final StubType stub,
      final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule, final RollDateAdjuster adjuster); static ZonedDateTime[] getAdjustedDateSchedule(
      ZonedDateTime startDate,
      ZonedDateTime endDate,
      Period schedulePeriod,
      StubType stub,
      BusinessDayConvention convention,
      Calendar calendar,
      RollDateAdjuster adjuster); static ZonedDateTime[] getAdjustedDateSchedule(
      final ZonedDateTime[] startDates,
      final Period schedulePeriod,
      final BusinessDayConvention businessDayConvention,
      final Calendar calendar,
      final RollDateAdjuster adjuster); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Frequency scheduleFrequency,
      final boolean stubShort, final boolean fromEnd, final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final Period tenorTotal, final Period tenorPeriod, final boolean stubShort,
      final boolean fromEnd, final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final Period tenorTotal, final boolean stubShort, final boolean fromEnd,
      final IborIndex index, final Calendar calendar); static ZonedDateTime[] getUnadjustedDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime maturityDate, final Frequency frequency); static ZonedDateTime[] getUnadjustedDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime accrualDate, final ZonedDateTime maturityDate,
      final Frequency frequency); static ZonedDateTime[] getUnadjustedDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime accrualDate, final ZonedDateTime maturityDate,
      final Period period); static ZonedDateTime[] getBackwardsUnadjustedDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime maturityDate, final Frequency frequency); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime[] dates, final BusinessDayConvention convention, final Calendar calendar); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime[] dates, final BusinessDayConvention convention, final Calendar calendar,
      final int settlementDays); static ZonedDateTime getAdjustedDate(final ZonedDateTime originalDate, final BusinessDayConvention convention, 
      final Calendar calendar, final int offset); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period period,
      final BusinessDayConvention businessDayConvention, final Calendar calendar, final boolean isEOM, final boolean stubShort); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Frequency frequency,
      final BusinessDayConvention businessDayConvention, final Calendar calendar, final boolean isEOM); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period period,
      final BusinessDayConvention businessDayConvention, final Calendar calendar, final boolean isEOM); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final Period tenor, final Period period,
      final BusinessDayConvention businessDayConvention, final Calendar calendar, final boolean isEOM, final boolean shortStub); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final Period tenorAnnuity, final Period periodPayments,
      final BusinessDayConvention businessDayConvention, final Calendar calendar, final boolean isEOM); static ZonedDateTime[] getSettlementDateSchedule(final ZonedDateTime[] dates, final Calendar calendar, final BusinessDayConvention businessDayConvention,
      final int settlementDays); static LocalDate[] getSettlementDateSchedule(final LocalDate[] dates, final Calendar calendar, final BusinessDayConvention businessDayConvention,
      final int settlementDays); static ZonedDateTime[] getAdjustedResetDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime[] dates, final BusinessDayConvention convention,
      final Calendar calendar, final int settlementDays); static ZonedDateTime[] getAdjustedMaturityDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime[] dates, final BusinessDayConvention convention,
      final Calendar calendar, final Frequency frequency); static double[] getTimes(final ZonedDateTime[] dates, final DayCount dayCount, final ZonedDateTime fromDate); static int numberOfNegativeValues(final double[] periods); static double[] removeFirstNValues(final double[] data, final int n); static double[] getYearFractions(final ZonedDateTime[] dates, final DayCount dayCount, final ZonedDateTime fromDate); static ZonedDateTime[] getStartDates(final ZonedDateTime startDate, final ZonedDateTime[] endDates);  }
@Test public void adjustedDateSchedule_rollEom_atEom_backwards_shortStub() { ZonedDateTime start = ZonedDateTime.of(2012, 4, 22, 0, 0, 0, 0, ZoneOffset.UTC); ZonedDateTime end = ZonedDateTime.of(2013, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC); Period freq = Period.ofMonths(3); RollDateAdjuster eom = EndOfMonthRollDateAdjuster.getAdjuster(); ZonedDateTime[] test = ScheduleCalculator.getAdjustedDateSchedule( start, end, freq, StubType.SHORT_START, MOD_FOL, CALENDAR, eom); assertEquals(5, test.length); assertEquals(ZonedDateTime.of(2012, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC), test[0]); assertEquals(ZonedDateTime.of(2012, 7, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[1]); assertEquals(ZonedDateTime.of(2012, 10, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[2]); assertEquals(ZonedDateTime.of(2013, 1, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[3]); assertEquals(ZonedDateTime.of(2013, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC), test[4]); }
@Test public void adjustedDateSchedule_rollEom_atEom_backwards_longStub() { ZonedDateTime start = ZonedDateTime.of(2012, 4, 22, 0, 0, 0, 0, ZoneOffset.UTC); ZonedDateTime end = ZonedDateTime.of(2013, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC); Period freq = Period.ofMonths(3); RollDateAdjuster eom = EndOfMonthRollDateAdjuster.getAdjuster(); ZonedDateTime[] test = ScheduleCalculator.getAdjustedDateSchedule( start, end, freq, StubType.LONG_START, MOD_FOL, CALENDAR, eom); assertEquals(4, test.length); assertEquals(ZonedDateTime.of(2012, 7, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[0]); assertEquals(ZonedDateTime.of(2012, 10, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[1]); assertEquals(ZonedDateTime.of(2013, 1, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[2]); assertEquals(ZonedDateTime.of(2013, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC), test[3]); }
@Test public void adjustedDateSchedule_rollEom_atEom_backwards_noStub() { ZonedDateTime start = ZonedDateTime.of(2012, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC); ZonedDateTime end = ZonedDateTime.of(2013, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC); Period freq = Period.ofMonths(3); RollDateAdjuster eom = EndOfMonthRollDateAdjuster.getAdjuster(); ZonedDateTime[] test = ScheduleCalculator.getAdjustedDateSchedule( start, end, freq, StubType.NONE, MOD_FOL, CALENDAR, eom); assertEquals(4, test.length); assertEquals(ZonedDateTime.of(2012, 7, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[0]); assertEquals(ZonedDateTime.of(2012, 10, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[1]); assertEquals(ZonedDateTime.of(2013, 1, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[2]); assertEquals(ZonedDateTime.of(2013, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC), test[3]); }
@Test public void adjustedDateSchedule_rollEom_atEom_forwards_shortStub() { ZonedDateTime start = ZonedDateTime.of(2012, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC); ZonedDateTime end = ZonedDateTime.of(2013, 5, 2, 0, 0, 0, 0, ZoneOffset.UTC); Period freq = Period.ofMonths(3); RollDateAdjuster eom = EndOfMonthRollDateAdjuster.getAdjuster(); ZonedDateTime[] test = ScheduleCalculator.getAdjustedDateSchedule( start, end, freq, StubType.SHORT_END, MOD_FOL, CALENDAR, eom); assertEquals(5, test.length); assertEquals(ZonedDateTime.of(2012, 7, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[0]); assertEquals(ZonedDateTime.of(2012, 10, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[1]); assertEquals(ZonedDateTime.of(2013, 1, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[2]); assertEquals(ZonedDateTime.of(2013, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC), test[3]); assertEquals(ZonedDateTime.of(2013, 5, 2, 0, 0, 0, 0, ZoneOffset.UTC), test[4]); }
@Test public void adjustedDateSchedule_rollEom_atEom_forwards_noStub() { ZonedDateTime start = ZonedDateTime.of(2012, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC); ZonedDateTime end = ZonedDateTime.of(2013, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC); Period freq = Period.ofMonths(3); RollDateAdjuster eom = EndOfMonthRollDateAdjuster.getAdjuster(); ZonedDateTime[] test = ScheduleCalculator.getAdjustedDateSchedule( start, end, freq, StubType.NONE, MOD_FOL, CALENDAR, eom); assertEquals(4, test.length); assertEquals(ZonedDateTime.of(2012, 7, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[0]); assertEquals(ZonedDateTime.of(2012, 10, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[1]); assertEquals(ZonedDateTime.of(2013, 1, 31, 0, 0, 0, 0, ZoneOffset.UTC), test[2]); assertEquals(ZonedDateTime.of(2013, 4, 30, 0, 0, 0, 0, ZoneOffset.UTC), test[3]); }
@Test public void adjustedDateSchedule_rollEom_notAtEom_backwards() { ZonedDateTime start = ZonedDateTime.of(2012, 4, 22, 0, 0, 0, 0, ZoneOffset.UTC); ZonedDateTime end = ZonedDateTime.of(2013, 1, 18, 0, 0, 0, 0, ZoneOffset.UTC); Period freq = Period.ofMonths(3); RollDateAdjuster eom = EndOfMonthRollDateAdjuster.getAdjuster(); ZonedDateTime[] test = ScheduleCalculator.getAdjustedDateSchedule( start, end, freq, StubType.SHORT_START, MOD_FOL, CALENDAR, eom); assertEquals(3, test.length); assertEquals(ZonedDateTime.of(2012, 7, 18, 0, 0, 0, 0, ZoneOffset.UTC), test[0]); assertEquals(ZonedDateTime.of(2012, 10, 18, 0, 0, 0, 0, ZoneOffset.UTC), test[1]); assertEquals(ZonedDateTime.of(2013, 1, 18, 0, 0, 0, 0, ZoneOffset.UTC), test[2]); }
@Test public void adjustedDateSchedule_rollEom_notAtEom_forwards() { ZonedDateTime start = ZonedDateTime.of(2012, 4, 22, 0, 0, 0, 0, ZoneOffset.UTC); ZonedDateTime end = ZonedDateTime.of(2013, 1, 18, 0, 0, 0, 0, ZoneOffset.UTC); Period freq = Period.ofMonths(3); RollDateAdjuster eom = EndOfMonthRollDateAdjuster.getAdjuster(); ZonedDateTime[] test = ScheduleCalculator.getAdjustedDateSchedule( start, end, freq, StubType.SHORT_END, MOD_FOL, CALENDAR, eom); assertEquals(3, test.length); assertEquals(ZonedDateTime.of(2012, 7, 23, 0, 0, 0, 0, ZoneOffset.UTC), test[0]); assertEquals(ZonedDateTime.of(2012, 10, 22, 0, 0, 0, 0, ZoneOffset.UTC), test[1]); assertEquals(ZonedDateTime.of(2013, 1, 18, 0, 0, 0, 0, ZoneOffset.UTC), test[2]); }
@Test public void adjustedDateSchedule_rollEom_noRoll_backwards() { ZonedDateTime start = ZonedDateTime.of(2012, 4, 22, 0, 0, 0, 0, ZoneOffset.UTC); ZonedDateTime end = ZonedDateTime.of(2013, 1, 18, 0, 0, 0, 0, ZoneOffset.UTC); Period freq = Period.ofMonths(3); ZonedDateTime[] test = ScheduleCalculator.getAdjustedDateSchedule( start, end, freq, StubType.SHORT_START, MOD_FOL, CALENDAR, null); assertEquals(3, test.length); assertEquals(ZonedDateTime.of(2012, 7, 18, 0, 0, 0, 0, ZoneOffset.UTC), test[0]); assertEquals(ZonedDateTime.of(2012, 10, 18, 0, 0, 0, 0, ZoneOffset.UTC), test[1]); assertEquals(ZonedDateTime.of(2013, 1, 18, 0, 0, 0, 0, ZoneOffset.UTC), test[2]); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDateArray1() { ScheduleCalculator.getAdjustedDateSchedule(null, new ModifiedFollowingBusinessDayConvention(), ALL, 0); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyDateArray1() { ScheduleCalculator.getAdjustedDateSchedule(new ZonedDateTime[0], new ModifiedFollowingBusinessDayConvention(), ALL, 0); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullConvention() { ScheduleCalculator.getAdjustedDateSchedule(new ZonedDateTime[] {DateUtils.getUTCDate(2010, 6, 1) }, null, ALL, 0); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullCalendar() { ScheduleCalculator.getAdjustedDateSchedule(new ZonedDateTime[] {DateUtils.getUTCDate(2010, 6, 1) }, new ModifiedFollowingBusinessDayConvention(), null, 0); }