class WeightedPercentile {

    public double evaluate(double percentile) {
        if (percentile >= 50.0) {
            int numToPass = (int)((100.0 - percentile) / 100.0 * numRawMetrics);
            int numPassed = 0;
            for (int i = weightedMetrics.length - 1; i >= 0; i--) {
                numPassed += weightedMetrics[i].count;
                if (numPassed >= numToPass) {
                    return weightedMetrics[i].metric;
                }
            }
        } else {
            int numToPass = (int)(percentile / 100.0 * numRawMetrics);
            int numPassed = 0;
            for (int i = 0; i < weightedMetrics.length; i++) {
                numPassed += weightedMetrics[i].count;
                if (numPassed >= numToPass) {
                    return weightedMetrics[i].metric;
                }
            }
        }
        throw new MacroBaseInternalError("WeightedPercentile was implemented incorrectly");
    }

    public  WeightedPercentile(double[] counts, double[] metrics);

}