All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.prometheus.metrics.model.snapshots.ClassicHistogramBucket Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
package io.prometheus.metrics.model.snapshots;

/**
 * Helper class for iterating over {@link ClassicHistogramBuckets}.
 * Note that the {@code count} is not cumulative.
 */
public class ClassicHistogramBucket implements Comparable {

    private final long count; // not cumulative
    private final double upperBound;

    public ClassicHistogramBucket(double upperBound, long count) {
        this.count = count;
        this.upperBound = upperBound;
        if (Double.isNaN(upperBound)) {
            throw new IllegalArgumentException("Cannot use NaN as an upper bound for a histogram bucket");
        }
        if (count < 0) {
            throw new IllegalArgumentException(count + ": " + ClassicHistogramBuckets.class.getSimpleName() + " cannot have a negative count");
        }
    }

    public long getCount() {
        return count;
    }

    public double getUpperBound() {
        return upperBound;
    }

    /**
     * For sorting a list of buckets by upper bound.
     */
    @Override
    public int compareTo(ClassicHistogramBucket other) {
        int result = Double.compare(upperBound, other.upperBound);
        if (result != 0) {
            return result;
        }
        return Long.compare(count, other.count);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy