public class FixedHistogram implements Histogram { private double _low, _high; /* From constructor*/ private int[] _count; /* Value counts */ /** A new histogram with SIZE buckets of values >= LOW and < HIGH. */ public FixedHistogram(int size, double low, double high) { if (low >= high || size <= 0) { throw new IllegalArgumentException(); } _low = low; _high = high; _count = new int[size]; } public int size() { return _count.length; } public double low(int k) { return _low + k * (_high - _low)/_count.length; } public int count(int k) { return _count[k]; } public void add(double val) { if (val >= _low && val < _high) { _count[(int) ((val - _low)/(_high - _low) * _count.length)] += 1; } } }