ISDACompliantScheduleGenerator { public static LocalDate[] getIntegrationNodesAsDates(final LocalDate startDate, final LocalDate endDate, final LocalDate[] disCurveDates, final LocalDate[] spreadCurveDates) { ArgumentChecker.notNull(startDate, "null startDate"); ArgumentChecker.notNull(endDate, "null endDate"); ArgumentChecker.noNulls(disCurveDates, "nulls in disCurveDates"); ArgumentChecker.noNulls(spreadCurveDates, "nulls in spreadCurveDates"); ArgumentChecker.isTrue(endDate.isAfter(startDate), "endDate of {} is not after startDate of {}", endDate.toString(), startDate.toString()); final int nDisCurvePoints = disCurveDates.length; final int nSpreadCurvePoints = spreadCurveDates.length; final LinkedHashSet<LocalDate> set = new LinkedHashSet<>(2 + nDisCurvePoints + nSpreadCurvePoints); set.add(startDate); for (final LocalDate date : disCurveDates) { set.add(date); } for (final LocalDate date : spreadCurveDates) { set.add(date); } set.add(endDate); final int n = set.size(); final LocalDate[] res = new LocalDate[n]; set.toArray(res); Arrays.sort(res); int a = 0; int b = n - 1; while (res[a].isBefore(startDate)) { a++; } while (res[b].isAfter(endDate)) { b--; } final int newLength = b - a + 1; if (newLength == n) { return res; } final LocalDate[] res2 = new LocalDate[newLength]; System.arraycopy(res, a, res2, 0, newLength); return res2; }  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 getIntegrationNodesAsDatesTest() { final LocalDate[] expected = new LocalDate[] {START_DATE, LocalDate.of(2013, 2, 23), LocalDate.of(2013, 3, 13), LocalDate.of(2013, 4, 12), LocalDate.of(2013, 4, 13), LocalDate.of(2014, 2, 17), LocalDate.of(2014, 7, 2), LocalDate.of(2015, 4, 30), END_DATE }; final int n = expected.length; LocalDate[] res = ISDACompliantScheduleGenerator.getIntegrationNodesAsDates(START_DATE, END_DATE, DISCOUNT_CURVE_DATES, SPREAD_CURVE_DATES); assertEquals("", n, res.length); for (int i = 0; i < n; i++) { assertTrue(expected[i].equals(res[i])); } final LocalDate lateStartDate = LocalDate.of(2013, 3, 13); final LocalDate[] expectedLateStart = new LocalDate[] {lateStartDate, LocalDate.of(2013, 4, 12), LocalDate.of(2013, 4, 13), LocalDate.of(2014, 2, 17), LocalDate.of(2014, 7, 2), LocalDate.of(2015, 4, 30), END_DATE }; final int nLateStart = expectedLateStart.length; res = ISDACompliantScheduleGenerator.getIntegrationNodesAsDates(lateStartDate, END_DATE, DISCOUNT_CURVE_DATES, SPREAD_CURVE_DATES); assertEquals(nLateStart, res.length); for (int i = 0; i < nLateStart; i++) { assertTrue(expectedLateStart[i].equals(res[i])); } final LocalDate lateEndDate = LocalDate.of(2018, 8, 30); final LocalDate[] discCurveDatesRe = new LocalDate[] {LocalDate.of(2013, 3, 13), LocalDate.of(2013, 4, 14), LocalDate.of(2013, 4, 12), LocalDate.of(2014, 7, 5), LocalDate.of(2015, 6, 30) }; final LocalDate[] expectedLateEnd = new LocalDate[] {START_DATE, LocalDate.of(2013, 2, 23), LocalDate.of(2013, 3, 13), LocalDate.of(2013, 4, 12), LocalDate.of(2013, 4, 13), LocalDate.of(2013, 4, 14), LocalDate.of(2014, 2, 17), LocalDate.of(2014, 7, 2), LocalDate.of(2014, 7, 5), LocalDate.of(2015, 4, 30), LocalDate.of(2015, 6, 30), LocalDate.of(2017, 4, 30), lateEndDate }; final int nLateEnd = expectedLateEnd.length; res = ISDACompliantScheduleGenerator.getIntegrationNodesAsDates(START_DATE, lateEndDate, discCurveDatesRe, SPREAD_CURVE_DATES); assertEquals(nLateEnd, res.length); for (int i = 0; i < nLateEnd; i++) { assertTrue(expectedLateEnd[i].equals(res[i])); } }