class DiscoveryIterator implements SortedKeyValueIterator<Key,Value> {

    @Override
    public void next() throws IOException {
        tk = null;
        tv = null;
        
        while (itr.hasTop() && tk == null) {
            Multimap<String,TermInfo> terms = aggregateDate();
            if (terms.isEmpty()) {
                if (log.isTraceEnabled())
                    log.trace("Couldn't aggregate index info; moving onto next date/field/term if data is available.");
                continue;
            } else {
                if (log.isTraceEnabled())
                    log.trace("Received term info multimap of size [" + terms.size() + "]");
                ArrayList<DiscoveredThing> things = newArrayList(filter(
                                transform(terms.asMap().values(), new TermInfoAggregation(separateCountsByColVis, showReferenceCount, reverseIndex)),
                                Predicates.notNull()));
                if (log.isTraceEnabled())
                    log.trace("After conversion to discovery objects, there are [" + things.size() + "] term info objects.");
                if (things.isEmpty()) {
                    continue;
                } else {
                    Pair<Key,Value> top = makeTop(things);
                    tk = top.getFirst();
                    tv = top.getSecond();
                    return;
                }
            }
        }
        if (log.isTraceEnabled())
            log.trace("No data found.");
    }

}