Here you can find the source of getHistogramBigInt(List
getHistogram
but operates on BigIntegers
.
public static List<Integer> getHistogramBigInt(List<BigInteger> data, int breaks)
//package com.java2s; /*//from ww w. j a v a2s .co m * Copyright 2008, Limewire Inc. * Copyrights licensed under the GPL License. */ import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { /** * Same as <code>getHistogram</code> but operates on <code>BigIntegers</code>. */ public static List<Integer> getHistogramBigInt(List<BigInteger> data, int breaks) { if (data.isEmpty()) { return Collections.emptyList(); } List<Integer> ret = new ArrayList<Integer>(breaks); for (int i = 0; i < breaks; i++) { ret.add(0); } BigInteger min = Collections.min(data); BigInteger max = Collections.max(data); BigInteger range = max.subtract(min).add(BigInteger.valueOf(1)); BigInteger step = range.divide(BigInteger.valueOf(breaks)); if (step.equals(BigInteger.ZERO)) { return Collections.emptyList(); // too small } for (BigInteger point : data) { int index = point.subtract(min).divide(step).intValue(); // Math.min necessary because rounding error -> AIOOBE index = Math.min(index, breaks - 1); ret.set(index, ret.get(index) + 1); } return ret; } }