Source:
private void createSummaryStatisticsFile(final Date startDate, final Date endDate, final Integer numDaysInPeriod) throws InterruptedException, ExecutionException { List<Statistics> csvStats = new ArrayList<Statistics>(); Calendar startDateCal = Calendar.getInstance(TimeZone.getTimeZone(ZoneOffset.UTC)); startDateCal.setTime(startDate); Calendar endDateCal = Calendar.getInstance(TimeZone.getTimeZone(ZoneOffset.UTC)); endDateCal.setTime(startDate); endDateCal.add(Calendar.DATE, numDaysInPeriod); while (endDate.compareTo(endDateCal.getTime()) >= 0) { LOGGER.info("Getting csvRecord for start date " + startDateCal.getTime().toString() + " end date " + endDateCal.getTime().toString()); System.out.println("Getting csvRecord for start date " + startDateCal.getTime().toString() + " end date " + endDateCal.getTime().toString()); DateRange csvRange = new DateRange(startDateCal.getTime(), new Date(endDateCal.getTimeInMillis())); Statistics historyStat = new Statistics(); historyStat.setDateRange(csvRange); Future<Statistics> futureEmailCsvStats = asynchronousStatisticsInitializor.getStatistics(csvRange); historyStat = futureEmailCsvStats.get(); csvStats.add(historyStat); LOGGER.info("Finished getting csvRecord for start date " + startDateCal.getTime().toString() + " end date " + endDateCal.getTime().toString()); System.out.println("Finished getting csvRecord for start date " + startDateCal.getTime().toString() + " end date " + endDateCal.getTime().toString()); startDateCal.add(Calendar.DATE, numDaysInPeriod); endDateCal.setTime(startDateCal.getTime()); endDateCal.add(Calendar.DATE, numDaysInPeriod); } LOGGER.info("Finished getting statistics"); System.out.println("Finished getting statistics"); StatsCsvFileWriter.writeCsvFile(props.getProperty("downloadFolderPath") + File.separator + props.getProperty("summaryEmailName", "summaryStatistics.csv"), csvStats); new File(props.getProperty("downloadFolderPath") + File.separator + props.getProperty("summaryEmailName", "summaryStatistics.csv")); }

Target:
private void createSummaryStatisticsFile(final Date startDate, final Date endDate, final Integer numDaysInPeriod) throws InterruptedException, ExecutionException { List<Statistics> csvStats = new ArrayList<Statistics>(); Calendar startDateCal = Calendar.getInstance(TimeZone.getTimeZone(ZoneOffset.UTC)); startDateCal.setTime(startDate); Calendar endDateCal = Calendar.getInstance(TimeZone.getTimeZone(ZoneOffset.UTC)); endDateCal.setTime(startDate); endDateCal.add(Calendar.DATE, numDaysInPeriod); while (endDate.compareTo(endDateCal.getTime()) >= 0) { LOGGER.info("Getting csvRecord for start date " + startDateCal.getTime().toString() + " end date " + endDateCal.getTime().toString()); DateRange csvRange = new DateRange(startDateCal.getTime(), new Date(endDateCal.getTimeInMillis())); Statistics historyStat = new Statistics(); historyStat.setDateRange(csvRange); Future<Statistics> futureEmailCsvStats = asynchronousStatisticsInitializor.getStatistics(csvRange); historyStat = futureEmailCsvStats.get(); csvStats.add(historyStat); LOGGER.info("Finished getting csvRecord for start date " + startDateCal.getTime().toString() + " end date " + endDateCal.getTime().toString()); startDateCal.add(Calendar.DATE, numDaysInPeriod); endDateCal.setTime(startDateCal.getTime()); endDateCal.add(Calendar.DATE, numDaysInPeriod); } LOGGER.info("Finished getting statistics"); StatsCsvFileWriter.writeCsvFile(props.getProperty("downloadFolderPath") + File.separator + props.getProperty("summaryEmailName", "summaryStatistics.csv"), csvStats); new File(props.getProperty("downloadFolderPath") + File.separator + props.getProperty("summaryEmailName", "summaryStatistics.csv")); }