IMMDateLogic { public static LocalDate getNextIndexRollDate(final LocalDate date) { final int day = date.getDayOfMonth(); final int month = date.getMonthValue(); final int year = date.getYear(); if (isIndexRollDate(date)) { if (month == INDEX_ROLL_MONTHS[0]) { return LocalDate.of(year, INDEX_ROLL_MONTHS[1], IMM_DAY); } else { return LocalDate.of(year + 1, INDEX_ROLL_MONTHS[0], IMM_DAY); } } else { if (month < INDEX_ROLL_MONTHS[0]) { return LocalDate.of(year, INDEX_ROLL_MONTHS[0], IMM_DAY); } else if (month == INDEX_ROLL_MONTHS[0]) { if (day < IMM_DAY) { return LocalDate.of(year, month, IMM_DAY); } else { return LocalDate.of(year, INDEX_ROLL_MONTHS[1], IMM_DAY); } } else if (month < INDEX_ROLL_MONTHS[1]) { return LocalDate.of(year, INDEX_ROLL_MONTHS[1], IMM_DAY); } else if (month == INDEX_ROLL_MONTHS[1]) { if (day < IMM_DAY) { return LocalDate.of(year, month, IMM_DAY); } else { return LocalDate.of(year + 1, INDEX_ROLL_MONTHS[0], IMM_DAY); } } else { return LocalDate.of(year + 1, INDEX_ROLL_MONTHS[0], IMM_DAY); } } }  static boolean isIMMDate(final LocalDate date); static boolean isIndexRollDate(final LocalDate date); static LocalDate[] getIMMDateSet(final LocalDate baseIMMDate, final Period[] tenors); static LocalDate[] getIMMDateSet(final LocalDate startIMMDate, final int size); static LocalDate getNextIMMDate(final LocalDate date); static LocalDate getPrevIMMDate(final LocalDate date); static LocalDate getNextIndexRollDate(final LocalDate date);  }
@Test public void getNextIndexRollDateTest() { final LocalDate[] dates = new LocalDate[] {LocalDate.of(2013, 3, 14), LocalDate.of(2013, 6, 20), LocalDate.of(2013, 3, 20), LocalDate.of(2013, 9, 20), LocalDate.of(2013, 1, 21), LocalDate.of(2013, 3, 21), LocalDate.of(2013, 9, 19), LocalDate.of(2013, 9, 21), LocalDate.of(2013, 11, 21) }; final LocalDate[] datesExp = new LocalDate[] {LocalDate.of(2013, 3, 20), LocalDate.of(2013, 9, 20), LocalDate.of(2013, 9, 20), LocalDate.of(2014, 3, 20), LocalDate.of(2013, 3, 20), LocalDate.of(2013, 9, 20), LocalDate.of(2013, 9, 20), LocalDate.of(2014, 3, 20), LocalDate.of(2014, 3, 20) }; for (int i = 0; i < dates.length; ++i) { assertEquals(IMMDateLogic.getNextIndexRollDate(dates[i]), datesExp[i]); } }