/** * Create a histogram from a set of ranges with associated event counters. * * @throws IllegalArgumentException If the items contain mixed signs. */ public Histogram(Stream<RangeWithCount> items) { final List<RangeWithCount> iter = cleanup_(items.map(RangeWithCount::clone).collect(Collectors.toList())); if (iter.isEmpty()) { buckets_ = EMPTY_LIST; return; } if (iter.stream() .map(RangeWithCount::getCount) .map(Math::signum) .distinct() .count() > 1) { throw new IllegalArgumentException("mixed sign"); } final List<Bucket> buckets = new ArrayList<>(iter.size()); double running_total = 0; for (RangeWithCount rwc : iter) { running_total += rwc.getCount(); buckets.add(new Bucket(rwc.getRange(), rwc.getCount(), running_total)); } buckets_ = unmodifiableList(buckets); }
/** * Create a histogram from a set of ranges with associated event counters. * * @throws IllegalArgumentException If the items contain mixed signs. */ public Histogram(Stream<RangeWithCount> items) { final List<RangeWithCount> iter = cleanup_(items.map(RangeWithCount::clone).collect(Collectors.toList())); if (iter.isEmpty()) { buckets_ = EMPTY_LIST; return; } if (iter.stream() .map(RangeWithCount::getCount) .map(Math::signum) .distinct() .count() > 1) { throw new IllegalArgumentException("mixed sign"); } final List<Bucket> buckets = new ArrayList<>(iter.size()); double running_total = 0; for (RangeWithCount rwc : iter) { running_total += rwc.getCount(); buckets.add(new Bucket(rwc.getRange(), rwc.getCount(), running_total)); } buckets_ = unmodifiableList(buckets); }