private void populatePartitionAndLocalReplicaMaps(Collection<? extends PartitionId> allPartitions,
        Map<String, SortedMap<Integer, List<PartitionId>>> partitionIdsByClassAndLocalReplicaCount,
        Map<PartitionId, List<ReplicaId>> partitionIdToLocalReplicas, String localDatacenterName) {
      for (PartitionId partition : allPartitions) {
        String partitionClass = partition.getPartitionClass();
        int localReplicaCount = 0;
        for (ReplicaId replicaId : partition.getReplicaIds()) {
          if (localDatacenterName != null && !localDatacenterName.isEmpty() && replicaId.getDataNodeId()
              .getDatacenterName()
              .equals(localDatacenterName)) {
            partitionIdToLocalReplicas.computeIfAbsent(partition, key -> new LinkedList<>()).add(replicaId);
            localReplicaCount++;
          }
        }
        SortedMap<Integer, List<PartitionId>> replicaCountToPartitionIds =
            partitionIdsByClassAndLocalReplicaCount.computeIfAbsent(partitionClass, key -> new TreeMap<>());
        replicaCountToPartitionIds.computeIfAbsent(localReplicaCount, key -> new ArrayList<>()).add(partition);
      }
    }
Populate partition-selection related maps that track partition and its replicas in local dc.
@param allPartitions all the partitions in cluster.
@param partitionIdsByClassAndLocalReplicaCount a map that tracks partitions sorted by local replica count.
@param partitionIdToLocalReplicas a map that tracks partition to its local replicas.
@param localDatacenterName the name of local dc. Can be null if dc specific replica counts are not required.
ambry-clustermap/src/main/java/com/github/ambry/clustermap/ClusterMapUtils.java