private static Map<TopicPartition, List<Integer>> calculateAssignment(Map<TopicPartition, List<Integer>> currentAssignment,
                                                                          List<BrokerMetadata> brokerMetadatas) {
        Map<String, List<Entry<TopicPartition, List<Integer>>>> groupedByTopic = new HashMap<>();
        for (Entry<TopicPartition, List<Integer>> e : currentAssignment.entrySet())
            groupedByTopic.computeIfAbsent(e.getKey().topic(), k -> new ArrayList<>()).add(e);
        Map<TopicPartition, List<Integer>> proposedAssignments = new HashMap<>();
        groupedByTopic.forEach((topic, assignment) -> {
            List<Integer> replicas = assignment.get(0).getValue();
            Map<Integer, List<Integer>> assignedReplicas = AdminUtils.
                assignReplicasToBrokers(brokerMetadatas, assignment.size(), replicas.size());
            assignedReplicas.forEach((partition, replicas0) ->
                proposedAssignments.put(new TopicPartition(topic, partition), replicas0));
        });
        return proposedAssignments;
    }
Calculate the new partition assignments to suggest in --generate.

@param currentAssignment  The current partition assignments.
@param brokerMetadatas    The rack information for each broker.

@return                   A map from partitions to the proposed assignments for each.
tools/src/main/java/org/apache/kafka/tools/reassign/ReassignPartitionsCommand.java