class 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)) { //on an index roll 
      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);
      }
    }
  }

}