ObjectHistogram implements Histogram<T, ObjectHistogram<T>>, DistributionComputer { @Override public TreeMap<Integer, Double> computeDistributionFunction() { TreeMap<Integer, Double> res = new TreeMap<>(); double accum = 0.0; for (Integer bucket : hist.keySet()) { accum += hist.get(bucket); res.put(bucket, accum); } return res; }  @Override void addElement(T val); @Override Set<Integer> buckets(); @Override Optional<Double> getValue(Integer bucketId); @Override TreeMap<Integer, Double> computeDistributionFunction(); @Override ObjectHistogram<T> plus(ObjectHistogram<T> other); @Override boolean isEqualTo(ObjectHistogram<T> other); abstract Integer mapToBucket(T obj); abstract Double mapToCounter(T obj); abstract ObjectHistogram<T> newInstance();  }
@Test public void testDistributionFunction() { TreeMap<Integer, Double> distribution = hist1.computeDistributionFunction(); int[] buckets = new int[distribution.size()]; double[] sums = new double[distribution.size()]; int ptr = 0; for (int bucket : distribution.keySet()) { sums[ptr] = distribution.get(bucket); buckets[ptr++] = bucket; } assertArrayEquals(new int[] {0, 1, 2, 3, 4, 5}, buckets); assertArrayEquals(new double[] {4., 7., 9., 10., 11., 12.}, sums, 0.01); }