Last active
August 21, 2017 14:52
-
-
Save Nimfadora/063593233e581796a918c106fc969161 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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