001package io.prometheus.metrics.model.snapshots; 002 003/** 004 * Helper class for iterating over {@link ClassicHistogramBuckets}. 005 * Note that the {@code count} is <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(count + ": " + ClassicHistogramBuckets.class.getSimpleName() + " cannot have a negative count"); 020 } 021 } 022 023 public long getCount() { 024 return count; 025 } 026 027 public double getUpperBound() { 028 return upperBound; 029 } 030 031 /** 032 * For sorting a list of buckets by upper bound. 033 */ 034 @Override 035 public int compareTo(ClassicHistogramBucket other) { 036 int result = Double.compare(upperBound, other.upperBound); 037 if (result != 0) { 038 return result; 039 } 040 return Long.compare(count, other.count); 041 } 042}