private static double computeCost(double[] stats) {
    if (stats == null || stats.length == 0) {
      return 0;
    }
    double totalCost = 0;
    double total = getSum(stats);

    double count = stats.length;
    double mean = total / count;
    for (int i = 0; i < stats.length; i++) {
      double n = stats[i];
      double diff = (mean - n) * (mean - n);
      totalCost += diff;
    }
    // No need to compute standard deviation with division by cluster size when scaling.
    totalCost = Math.sqrt(totalCost);
    return CostFunction.scale(getMinSkew(total, count), getMaxSkew(total, count), totalCost);
  }
We do not want to introduce a getCosts method to let upper layer get the cost array directly,
so here we introduce this method to take a {@link Consumer} as parameter, where we will pass
the actual cost array in, so you can change the element of the cost array in the
{@link Consumer} implementation.
<p/>
Usually, in prepare method, you need to fill all the elements of the cost array, while in
regionMoved method, you just need to update the element for the effect region servers.
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/DoubleArrayCost.java