Java BigInteger Calculate getHistogramBigInt(List data, int breaks)

Here you can find the source of getHistogramBigInt(List data, int breaks)

Description

Same as getHistogram but operates on BigIntegers.

License

GNU General Public License

Declaration

public static List<Integer> getHistogramBigInt(List<BigInteger> data, int breaks) 

Method Source Code

//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;
    }
}

Related

  1. getCreateLocalNextHopJobKey(Long vpnId, BigInteger dpnId, String prefix)
  2. getDateOf(BigInteger fileTime)
  3. getDateOf(final BigInteger fileTime)
  4. getDigitCount(BigInteger number)
  5. getHexString(BigInteger bigInt)
  6. getIntegral(String number, BigInteger def)
  7. getInterfaceName(final BigInteger datapathid, final String portName, final Integer vlanId)
  8. getIpAddressByBigInteger(BigInteger[] bigs)
  9. getIpv4AddrFromNumber(BigInteger addr)