Skip to content

Instantly share code, notes, and snippets.

@davideanastasia
Created September 3, 2019 06:02
Show Gist options
  • Save davideanastasia/a63bd2380dde072de62988b1c6c12c5f to your computer and use it in GitHub Desktop.
Save davideanastasia/a63bd2380dde072de62988b1c6c12c5f to your computer and use it in GitHub Desktop.
TiledSessions.java
@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