@Override public Iterable<Tuple2<CorrelatedEvents, Void>> call(Tuple2<List<StandardEvent>, List<StandardEvent>> t) throws Exception { List<Tuple2<CorrelatedEvents, Void>> results = new ArrayList<Tuple2<CorrelatedEvents, Void>>(); List<StandardEvent> alerts = t._1(); List<StandardEvent> clicks = t._2(); for (StandardEvent alert : alerts) { List<StandardEvent> correlated = new ArrayList<StandardEvent>(); for (StandardEvent click : clicks) { if (Math.abs(alert.getTimestamp() - click.getTimestamp()) <= FIVE_MIN_MILLIS) { correlated.add(click); } } if (!correlated.isEmpty()) { results.add(new Tuple2(CorrelatedEvents.newBuilder() .setEvent(alert) .setCorrelated(correlated) .build(), null)); } } return results; } });