ISDACompliantScheduleGenerator { public static LocalDate[] truncateList(final LocalDate startDate, final LocalDate endDate, final LocalDate[] dateList) { ArgumentChecker.notNull(startDate, "null startDate"); ArgumentChecker.notNull(endDate, "null endDate"); ArgumentChecker.noNulls(dateList, "nulls in dateList"); ArgumentChecker.isTrue(endDate.isAfter(startDate), "require enddate after startDate"); final int n = dateList.length; if (n == 0) { return new LocalDate[] {startDate, endDate }; } final List<LocalDate> temp = new ArrayList<>(n + 2); for (final LocalDate d : dateList) { if (d.isAfter(startDate) && d.isBefore(endDate)) { temp.add(d); } } final int m = temp.size(); final LocalDate[] tArray = new LocalDate[m]; temp.toArray(tArray); final LocalDate[] res = new LocalDate[m + 2]; res[0] = startDate; System.arraycopy(tArray, 0, res, 1, m); res[m + 1] = endDate; return res; }  static LocalDate[] getIntegrationNodesAsDates(final LocalDate startDate, final LocalDate endDate, final LocalDate[] disCurveDates, final LocalDate[] spreadCurveDates); static double[] getIntegrationNodesAsTimes(final LocalDate today, final LocalDate startDate, final LocalDate endDate, final LocalDate[] disCurveDates, final LocalDate[] spreadCurveDates); static LocalDate[] truncateList(final LocalDate startDate, final LocalDate endDate, final LocalDate[] dateList); static double[] getYearFractionFromToday(final LocalDate today, final LocalDate[] dates); static double[] getYearFractionFromToday(final LocalDate today, final LocalDate[] dates, final DayCount dayCount);  }
@Test public void truncateListTest() { final LocalDate[] dateList = new LocalDate[] {LocalDate.of(1912, 2, 29), LocalDate.of(1013, 12, 13), LocalDate.of(2000, 2, 2), LocalDate.of(2014, 7, 2), LocalDate.of(2015, 12, 30) }; final LocalDate startDate = LocalDate.of(1992, 2, 13); final LocalDate endDate = LocalDate.of(2015, 6, 30); LocalDate[] expected = new LocalDate[] {startDate, LocalDate.of(2000, 2, 2), LocalDate.of(2014, 7, 2), endDate }; int n = expected.length; LocalDate[] res = ISDACompliantScheduleGenerator.truncateList(startDate, endDate, dateList); assertEquals(n, res.length); for (int i = 0; i < n; ++i) { assertTrue(expected[i].isEqual(res[i])); } final LocalDate[] emptyDateList = new LocalDate[] {}; expected = new LocalDate[] {startDate, endDate }; n = expected.length; res = ISDACompliantScheduleGenerator.truncateList(startDate, endDate, emptyDateList); assertEquals(n, res.length); for (int i = 0; i < n; ++i) { assertTrue(expected[i].isEqual(res[i])); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void truncateListNullStartTest() { final LocalDate[] dateList = new LocalDate[] {LocalDate.of(1912, 2, 29), LocalDate.of(1013, 12, 13), LocalDate.of(2000, 2, 2), LocalDate.of(2014, 7, 2), LocalDate.of(2015, 12, 30) }; final LocalDate startDate = null; final LocalDate endDate = LocalDate.of(2015, 6, 30); ISDACompliantScheduleGenerator.truncateList(startDate, endDate, dateList); }
@Test(expectedExceptions = IllegalArgumentException.class) public void truncateListNullEndTest() { final LocalDate[] dateList = new LocalDate[] {LocalDate.of(1912, 2, 29), LocalDate.of(1013, 12, 13), LocalDate.of(2000, 2, 2), LocalDate.of(2014, 7, 2), LocalDate.of(2015, 12, 30) }; final LocalDate startDate = LocalDate.of(1992, 2, 13); final LocalDate endDate = null; ISDACompliantScheduleGenerator.truncateList(startDate, endDate, dateList); }
@Test(expectedExceptions = IllegalArgumentException.class) public void truncateListNullListTest() { final LocalDate[] dateList = null; final LocalDate startDate = LocalDate.of(1992, 2, 13); final LocalDate endDate = LocalDate.of(2015, 6, 30); ISDACompliantScheduleGenerator.truncateList(startDate, endDate, dateList); }
@Test(expectedExceptions = IllegalArgumentException.class) public void truncateListStartAfterEndTest() { final LocalDate[] dateList = new LocalDate[] {LocalDate.of(1912, 2, 29), LocalDate.of(1013, 12, 13), LocalDate.of(2000, 2, 2), LocalDate.of(2014, 7, 2), LocalDate.of(2015, 12, 30) }; final LocalDate startDate = LocalDate.of(2022, 2, 13); final LocalDate endDate = LocalDate.of(2015, 6, 30); ISDACompliantScheduleGenerator.truncateList(startDate, endDate, dateList); }