public void addBin(long value, double start, double end) { bins.add(new Bin(value, start, end)); }
private List<Bin> collect(List<Bin> bins, double startValue, double endValue) { int startBin = Double.NEGATIVE_INFINITY != startValue ? binNumberFor(startValue) : 0; int endBin = Double.POSITIVE_INFINITY != endValue ? binNumberFor(endValue) : bins.size(); if (endBin > bins.size()) { endBin = bins.size(); } List<Bin> collected = startBin < bins.size() ? bins.subList(startBin, endBin) : Collections.<Bin>emptyList(); if (collected.isEmpty()) { return Collections.singletonList(new Bin(0, startValue, endValue)); } return collected; }
static Bin collapse(List<Bin> bins) { long total = 0L; for (Bin b : bins) { total += b.getCount(); } Bin firstBin = bins.get(0); Bin lastBin = bins.get(bins.size() - 1); return new Bin(total, firstBin.getStart(), lastBin.getEnd()); }
private Bin emptyBinAt(int index) { BinDefinition binDef = definition.getBinDefinition(index); return new Bin(0, binDef.getStart(), binDef.getEnd()); }
private List<Bin> growTo(List<Bin> bins, double endValue, int minCount) { int neededBins = Double.POSITIVE_INFINITY != endValue ? definition.getBinForValue(endValue) : minCount; if (neededBins < minCount) { neededBins = minCount; } List<Bin> grownBins = new ArrayList<Bin>(bins); if (grownBins.isEmpty()) { grownBins.add(emptyBinAt(0)); } if (grownBins.get(0).getStart() != 0) { // fill bins from 0 to start double fillTo = grownBins.get(0).getStart(); List<Bin> prefixBins = new ArrayList<Bin>(); BinDefinition binDef; int count = 0; do { binDef = definition.getBinDefinition(count); count++; prefixBins.add(new Bin(0, binDef.getStart(), binDef.getEnd())); } while (fillTo > binDef.getEnd()); grownBins.addAll(0, prefixBins); } // fill bins from end to needed bins while (grownBins.size() < neededBins) { grownBins.add(emptyBinAt(grownBins.size())); } return Collections.unmodifiableList(grownBins); }
Bin binInstance=new Bin(mappedValue, mappedBin.getStart(), mappedBin.getEnd()); Bin prev=binsMap.put(Integer.valueOf(mappedIndex), binInstance); if (prev != null) { if (binValue == null) { BinDefinition mappedBin=def.getBinDefinition(mappedIndex); binValue = new Bin(0L, mappedBin.getStart(), mappedBin.getEnd());
public Histogram build() { SparseHistogram sparseMetric=metricValue.getHistogram(); Histogram metricHistogram=sparseMetric.getFullHistogram(definition); List<Bin> rawBins = growTo(metricHistogram.getBins(), end, binsCount); List<Bin> histBins = new ArrayList<Bin>(); int binCount = this.binsCount; // force start and end to bin boundaries double startHistory = definition.getBinDefinition(definition.getBinForValue(this.start)).getStart(); double endHistory = definition.getBinDefinition(definition.getBinForValue(this.end)).getEnd(); if (lowOutliers) { binCount--; histBins.add(new Bin(collapse(collect(rawBins, Double.NEGATIVE_INFINITY, startHistory)).getCount(), Double.NEGATIVE_INFINITY, startHistory)); } if (highOutliers) { binCount--; histBins.add(new Bin(collapse(collect(rawBins, endHistory, Double.POSITIVE_INFINITY)).getCount(), endHistory, Double.POSITIVE_INFINITY)); } histBins.addAll(toSize(collect(rawBins, startHistory, endHistory), binCount)); Collections.sort(histBins); return new Histogram(histBins); }