com.kolibrifx.plovercrest.server.streams.folds.HistoricalCombinatorStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plovercrest-server Show documentation
Show all versions of plovercrest-server Show documentation
Plovercrest server library.
The newest version!
/*
* Copyright (c) 2010-2017, KolibriFX AS. Licensed under the Apache License, version 2.0.
*/
package com.kolibrifx.plovercrest.server.streams.folds;
import java.util.Collection;
import com.kolibrifx.plovercrest.server.internal.folds.FoldCallback;
import com.kolibrifx.plovercrest.server.internal.folds.PeekableInputStream;
/**
* @see com.kolibrifx.plovercrest.server.folds.FoldCombinators#historical()
*/
public class HistoricalCombinatorStrategy implements CombinatorStrategy {
@Override
public boolean tryConsumeNext(final Collection extends PeekableInputStream extends T>> feeds,
final FoldCallback super T> cb) {
if (feeds.isEmpty()) {
return false;
}
PeekableInputStream extends T> best = null;
for (final PeekableInputStream extends T> feed : feeds) {
if (!feed.hasNext()) {
// Missing data from one table. For this strategy, both is a no go.
// This guarantees that timestamps are triggered in order.
cb.onEnd();
return false;
}
if (best == null || feed.nextTimestamp() < best.nextTimestamp()) {
best = feed;
}
}
assert best != null && best.hasNext();
best.consumeNext(cb);
return true;
}
}