001package io.prometheus.metrics.model.snapshots; 002 003/** 004 * Helper class for iterating over {@link ClassicHistogramBuckets}. Note that the {@code count} is 005 * <i>not</i> cumulative. 006 */ 007public class ClassicHistogramBucket implements Comparable<ClassicHistogramBucket> { 008 009 private final long count; // not cumulative 010 private final double upperBound; 011 012 public ClassicHistogramBucket(double upperBound, long count) { 013 this.count = count; 014 this.upperBound = upperBound; 015 if (Double.isNaN(upperBound)) { 016 throw new IllegalArgumentException("Cannot use NaN as an upper bound for a histogram bucket"); 017 } 018 if (count < 0) { 019 throw new IllegalArgumentException( 020 count 021 + ": " 022 + ClassicHistogramBuckets.class.getSimpleName() 023 + " cannot have a negative count"); 024 } 025 } 026 027 public long getCount() { 028 return count; 029 } 030 031 public double getUpperBound() { 032 return upperBound; 033 } 034 035 /** For sorting a list of buckets by upper bound. */ 036 @Override 037 public int compareTo(ClassicHistogramBucket other) { 038 int result = Double.compare(upperBound, other.upperBound); 039 if (result != 0) { 040 return result; 041 } 042 return Long.compare(count, other.count); 043 } 044}