private SortedMap < String , List < QueryResult > > splitQueryResultsByTime ( Iterable < QueryResult > results ) { SortedMap < String , List < QueryResult > > resultsByTime = new TreeMap < String , List < QueryResult > > ( ) ; for ( QueryResult result : results ) { String epoch = String . valueOf ( result . getEpoch ( TimeUnit . SECONDS ) ) ; if ( resultsByTime . containsKey ( epoch ) ) { List < QueryResult > current = resultsByTime . get ( epoch ) ; current . add ( result ) ; resultsByTime . put ( epoch , current ) ; } else { ArrayList < QueryResult > newQueryList = new ArrayList < QueryResult > ( ) ; newQueryList . add ( result ) ; resultsByTime . put ( epoch , newQueryList ) ; } } return resultsByTime ; }
Often query results for a given query come in batches so we need to split them up by time