Created
September 3, 2019 06:02
-
-
Save davideanastasia/a63bd2380dde072de62988b1c6c12c5f to your computer and use it in GitHub Desktop.
TiledSessions.java
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
@Override | |
public void mergeWindows(MergeContext c) throws Exception { | |
List<TiledIntervalWindow> sortedWindows = Lists.newArrayList(c.windows()); | |
switch (strategy) { | |
case SPACE_AND_TIME: | |
sortedWindows.sort(TiledIntervalWindow.SPACE_AND_TIME_COMPARATOR); | |
break; | |
case TIME_ONLY: | |
sortedWindows.sort(TiledIntervalWindow.TIME_ONLY_COMPARATOR); | |
break; | |
} | |
List<TiledIntervalWindowAccumulator> merges = Lists.newArrayList(); | |
TiledIntervalWindowAccumulator accumulator = new TiledIntervalWindowAccumulator(); | |
for (TiledIntervalWindow currentWindow : sortedWindows) { | |
if (accumulator.intersects(currentWindow)) { | |
accumulator.add(currentWindow); | |
} else { | |
merges.add(accumulator); | |
accumulator = new TiledIntervalWindowAccumulator(currentWindow); | |
} | |
} | |
merges.add(accumulator); | |
for (TiledIntervalWindowAccumulator merge : merges) { | |
merge.apply(c); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment