/** * Create a new {@link StreamCombiner} from the given streams * * @param a * first stream * @param b * second stream * @return the combined stream */ public static <A, B> StreamCombiner<A, B> combine(Stream<A> a, Stream<B> b) { return new StreamCombiner<A, B>(a, b); }
class Starter<T> implements Callable<T> { private Stream<T> stream; public Starter(Stream<T> a) { stream = a; } @Override public T call() throws Exception { return stream.next(); } }
/** * Utility method to combine two streams. The keys from the first * {@link Stream} will be prefixed "a" and the second "b". * * @param a * the first stream * @param b * the second stream * @return the combined stream */ public static Stream<Context> combine(Stream<Context> a, Stream<Context> b) { return new ContextStreamCombiner(a, b); } }
.combine(twitterUserWordCountStream, yahooAveragePriceStream) .map( new IncrementalLearnerWorldSelectingEvaluator(new SumLossEvaluator(),
@Override public T next() { final T toRet = this.streams.get(currentStream).next(); nextStream(); return toRet; }
@Override public Context next() { final Future<Context> futurea = this.service.submit(new Starter(a)); final Future<Context> futureb = this.service.submit(new Starter(b)); try { final Context a = futurea.get(); final Context b = futureb.get(); return a.combine(b, aprefix, bprefix); } catch (final Exception e) { e.printStackTrace(); } return null; }
.combine(twitterUserWordCountStream, yahooAveragePriceStream) .map( new IncrementalLearnerWorldSelectingEvaluator(new SumLossEvaluator(),