Source:
<code>private Batch fetch(Date lastNextStartTime) throws RetryableException { Map<String, Change> changesByTitle = new LinkedHashMap<>(); ConsumerRecords<String, ChangeEvent> records; Map<String, Long> timesByTopic = <START> Maps.newHashMapWithExpectedSize(topics.size()); <END> while (true) { try { records = consumer.poll(0); } catch (InterruptException | WakeupException e) { throw new RetryableException("Error fetching recent changes", e); } int count = records.count(); log.info("Fetched records from Kafka", count); if (count == 0) { break; } boolean foundSomething = false; for (ConsumerRecord<String, ChangeEvent> record: records) { ChangeEvent event = record.value(); String topic = record.topic(); if (!event.domain().equals(uris.getHost())) { continue; } if (!uris.isEntityNamespace(event.namespace())) { continue; } foundSomething = true; timesByTopic.put(topic, Math.max( event.timestamp().getTime(), timesByTopic.getOrDefault(topic, -1L))); Change change = new Change(event.title(), event.revision(), event.timestamp(), -1L); Change dupe = changesByTitle.put(change.entityId(), change); if (dupe != null && (dupe.revision() > change.revision() || dupe.revision() < 0)) { changesByTitle.remove(change.entityId()); changesByTitle.put(change.entityId(), dupe); } } if (changesByTitle.size() >= batchSize) { break; } if (changesByTitle.size() > 0 && !foundSomething) { log.info("Did not find anything useful in this batch, returning existing data"); break; } } long nextStartTime = timesByTopic.values().stream().min(Long::compareTo).orElse(-1L); final ImmutableList<Change> changes = ImmutableList.copyOf(changesByTitle.values()); log.info("Found changes", changes.size()); long advanced = nextStartTime - lastNextStartTime.getTime(); if (nextStartTime == -1L) { advanced = 0; nextStartTime = lastNextStartTime.getTime(); } String upTo = inputDateFormat().format(new Date(nextStartTime - 1000)); return new Batch(changes, advanced, upTo, new Date(nextStartTime)); }</code><technical_language>static import</technical_language>

Target:
private Batch fetch(Date lastNextStartTime) throws RetryableException { Map<String, Change> changesByTitle = new LinkedHashMap<>(); ConsumerRecords<String, ChangeEvent> records; Map<String, Date> timesByTopic = newHashMapWithExpectedSize(topics.size()); while (true) { try { records = consumer.poll(0); } catch (InterruptException | WakeupException e) { throw new RetryableException("Error fetching recent changes", e); } int count = records.count(); log.info("Fetched records from Kafka", count); if (count == 0) { break; } boolean foundSomething = false; for (ConsumerRecord<String, ChangeEvent> record: records) { ChangeEvent event = record.value(); String topic = record.topic(); if (!event.domain().equals(uris.getHost())) { continue; } if (!uris.isEntityNamespace(event.namespace())) { continue; } foundSomething = true; timesByTopic.put(topic, dateMax(new Date(record.timestamp()), timesByTopic.getOrDefault(topic, null))); Change change = new Change(event.title(), event.revision(), event.timestamp(), -1L); Change dupe = changesByTitle.put(change.entityId(), change); if (dupe != null && change.revision() >= 0 && (dupe.revision() > change.revision() || dupe.revision() < 0)) { changesByTitle.remove(change.entityId()); changesByTitle.put(change.entityId(), dupe); } } if (changesByTitle.size() >= batchSize) { break; } if (changesByTitle.size() > 0 && !foundSomething) { log.info("Did not find anything useful in this batch, returning existing data"); break; } } long nextStartTime = timesByTopic.values().stream().min(Date::compareTo) .orElse(lastNextStartTime).getTime(); final ImmutableList<Change> changes = ImmutableList.copyOf(changesByTitle.values()); log.info("Found changes", changes.size()); long advanced = nextStartTime - lastNextStartTime.getTime(); String upTo = inputDateFormat().format(new Date(nextStartTime - 1000)); return new Batch(changes, advanced, upTo, new Date(nextStartTime)); }