Source:
boolean refreshTopologyUnlocked(final Partition[] assignedPartitions) { final Map<EventTypePartition, Partition> newAssigned = Stream.of(assignedPartitions) .filter(p -> p.getState() == Partition.State.ASSIGNED) .collect(Collectors.toMap(Partition::getKey, p -> p)); final Map<EventTypePartition, Partition> newReassigning = Stream.of(assignedPartitions) .filter(p -> p.getState() == Partition.State.REASSIGNING) .collect(Collectors.toMap(Partition::getKey, p -> p)); boolean modified = false; final List<EventTypePartition> forciblyRemoved = offsets.keySet().stream() .filter(e -> !newAssigned.containsKey(e)) .filter(e -> !newReassigning.containsKey(e)) .collect(Collectors.toList()); if (!forciblyRemoved.isEmpty()) { modified = true; forciblyRemoved.forEach(this::removeFromStreaming); } final List<EventTypePartition> removedFromReassign = releasingPartitions.keySet().stream() .filter(p -> !newReassigning.containsKey(p)) .collect(Collectors.toList()); if (!removedFromReassign.isEmpty()) { modified = true; removedFromReassign.forEach(releasingPartitions::remove); } modified |= !newReassigning.keySet().stream() .map(this::addPartitionToReassigned) .filter(v -> v) .collect(Collectors.toList()).isEmpty(); final List<Partition> newAssignedPartitions = newAssigned.values() .stream() .filter(p -> !offsets.containsKey(p.getKey())) .collect(Collectors.toList()); if (!newAssignedPartitions.isEmpty()) { modified = true; newAssignedPartitions.forEach(this::addToStreaming); } if (modified) { reassignCommitted(); reconfigureKafkaConsumer(false); logPartitionAssignment("Topology refreshed"); } return modified; }

Target:
boolean refreshTopologyUnlocked(final Partition[] assignedPartitions) { final Map<EventTypePartition, Partition> newAssigned = Stream.of(assignedPartitions) .filter(p -> p.getState() == Partition.State.ASSIGNED) .collect(Collectors.toMap(Partition::getKey, p -> p)); final Map<EventTypePartition, Partition> newReassigning = Stream.of(assignedPartitions) .filter(p -> p.getState() == Partition.State.REASSIGNING) .collect(Collectors.toMap(Partition::getKey, p -> p)); boolean modified = false; final List<EventTypePartition> forciblyRemoved = offsets.keySet().stream() .filter(e -> !newAssigned.containsKey(e)) .filter(e -> !newReassigning.containsKey(e)) .collect(Collectors.toList()); if (!forciblyRemoved.isEmpty()) { modified = true; forciblyRemoved.forEach(this::removeFromStreaming); } final List<EventTypePartition> removedFromReassign = releasingPartitions.keySet().stream() .filter(p -> !newReassigning.containsKey(p)) .collect(Collectors.toList()); if (!removedFromReassign.isEmpty()) { modified = true; removedFromReassign.forEach(releasingPartitions::remove); } modified |= !newReassigning.keySet().stream() .filter(this::addPartitionToReassigned) .collect(Collectors.toList()).isEmpty(); final List<Partition> newAssignedPartitions = newAssigned.values() .stream() .filter(p -> !offsets.containsKey(p.getKey())) .collect(Collectors.toList()); if (!newAssignedPartitions.isEmpty()) { modified = true; newAssignedPartitions.forEach(this::addToStreaming); } if (modified) { reassignCommitted(); reconfigureKafkaConsumer(false); logPartitionAssignment("Topology refreshed"); } return modified; }