private List<TopicIdPartition> sortTopicIdPartitions(Collection<TopicIdPartition> topicIdPartitions) {
        Comparator<TopicIdPartition> comparator = Comparator
            .comparingDouble((TopicIdPartition topicIdPartition) -> {
                int totalPartitions = subscribedTopicDescriber.numPartitions(topicIdPartition.topicId());
                int totalSubscribers = membersPerTopic.get(topicIdPartition.topicId()).size();
                return (double) totalPartitions / totalSubscribers;
            })
            .reversed()
            .thenComparingInt(topicIdPartition -> membersPerTopic.get(topicIdPartition.topicId()).size())
            .thenComparingInt(TopicIdPartition::partitionId);

        return topicIdPartitions.stream()
            .sorted(comparator)
            .collect(Collectors.toList());
    }
<li> TopicIdPartitions are sorted in descending order based on the value:
      totalPartitions/number of subscribed members. </li>
<li> If the above value is the same then topicIdPartitions are sorted in
     ascending order of number of subscribers. </li>
<li> If both criteria are the same, sort in ascending order of the partition Id.
     This last criteria is for predictability of the assignments. </li>

@param topicIdPartitions       The topic partitions that need to be sorted.
@return A list of sorted topic partitions.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/UniformHeterogeneousAssignmentBuilder.java