Skip to content

Instantly share code, notes, and snippets.

@Nimfadora
Last active August 21, 2017 14:52
Show Gist options
  • Save Nimfadora/063593233e581796a918c106fc969161 to your computer and use it in GitHub Desktop.
Save Nimfadora/063593233e581796a918c106fc969161 to your computer and use it in GitHub Desktop.
public class TestBiFunction {
public static void main(String ... args){
//don't want to resolve dates in constructor -> compile error
List<GroovyReportTask> reportTasks = ReportUtils.splitInterval(firstDay, today,
(dtStart, dtEnd) -> new GroovyReportTask(getScriptFile(), null, dtStart, dtEnd));
}
public static <T extends ReportTask> List<T> splitInterval(Date startDay, Date endDayExclusive, int interval, BiFunction<Date, Date, T> builderForDay) {
Date startOfEndDay = DateUtil.startOfGMTDay(endDayExclusive);
List<T> res = Lists.newArrayList();
Date startTask = DateUtil.startOfGMTDay(startDay);
Date endTask = DateUtils.addDays(startTask, interval);
while (endTask.before(startOfEndDay)) {
res.add(builderForDay.apply(startTask, endTask));
startTask = DateUtils.addDays(startTask, interval);
endTask = DateUtils.addDays(startTask, interval);
}
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment