class 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;
  }

}