List of usage examples for com.google.common.collect ImmutableSortedMultiset naturalOrder
public static <E extends Comparable<?>> Builder<E> naturalOrder()
From source file:com.github.rinde.rinsim.scenario.measure.Metrics.java
/** * Computes a histogram for the inputs. The result is a multiset with an entry * for each bin in ascending order, the count of each entry indicates the size * of the bin. A bin is indicated by its leftmost value, for example if the * <code>binSize</code> is <code>2</code> and the result contains * <code>4</code> with count <code>3</code> this means that there are * <code>3</code> values in range <code>2 ≤ x < 4</code>. * @param input The values to compute the histogram of. * @param binSize The size of the bins./* w ww . j av a2s . c o m*/ * @return An {@link ImmutableSortedMultiset} representing the histogram. */ public static ImmutableSortedMultiset<Double> computeHistogram(Iterable<Double> input, double binSize) { final ImmutableSortedMultiset.Builder<Double> builder = ImmutableSortedMultiset.naturalOrder(); for (final double d : input) { checkArgument(!Double.isInfinite(d) && !Double.isNaN(d), "Only finite numbers are accepted, found %s.", d); builder.add(Math.floor(d / binSize) * binSize); } return builder.build(); }