List<PartitionId> getPartitionsWithState(String partitionClass, Predicate<PartitionState> stateCriteria,
        String criteriaStr) {
      List<PartitionId> suitablePartitions = new ArrayList<>();
      List<PartitionId> healthySuitablePartitions = new ArrayList<>();
      for (PartitionId partition : getPartitionsInClass(partitionClass, true)) {
        if (stateCriteria.test(partition.getPartitionState())) {
          suitablePartitions.add(partition);
          if (areAllReplicasForPartitionUp((partition))) {
            healthySuitablePartitions.add(partition);
          }
        } else {
          logger.debug("{} doesn't meet {} criteria, skipping it", partition, criteriaStr);
        }
      }
      return healthySuitablePartitions.isEmpty() ? suitablePartitions : healthySuitablePartitions;
    }
Returns all the partitions that meet the specified stateCriteria AND have the highest number of
replicas in the local datacenter for the given {@code partitionClass}.
<p/>
Also attempts to return only partitions with healthy replicas but if no such partitions are found, returns all
the eligible partitions irrespective of replica health.
<p/>
If {@code partitionClass} is {@code null}, gets partitions from all partition classes.
@param partitionClass the class of the partitions desired. Can be {@code null}.
@param stateCriteria {@link Predicate} that specifies the selection criteria for the partition based on {@link PartitionState}.
@param criteriaStr String representing a name for stateCriteria for logging.
@return all the writable partitions in {@code partitionClass} with the highest replica count in the local
datacenter (all writable partitions if it is {@code null}).
ambry-clustermap/src/main/java/com/github/ambry/clustermap/ClusterMapUtils.java