@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Bin other = (Bin) obj; if (getCount() != other.getCount()) return false; if (Double.doubleToLongBits(getStart()) != Double.doubleToLongBits(other.getStart())) return false; if (Double.doubleToLongBits(getStart()) != Double.doubleToLongBits(other.getStart())) return false; return true; }
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); }
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); }
public void addBin(long value, double start, double end) { bins.add(new Bin(value, start, end)); }
/** * @return the starting range for the entire {@link Histogram}. All values * within all bins will be >= this value; */ public double getStart() { if (bins.isEmpty()) { return Double.NEGATIVE_INFINITY; } else { return bins.get(0).getStart(); } }
/** * @return the end range for the entire {@link Histogram}. All values within * all bins will be < this value */ public double getEnd() { if (bins.isEmpty()) { return Double.POSITIVE_INFINITY; } else { return bins.get(bins.size() - 1).getEnd(); } }
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; }
private Bin emptyBinAt(int index) { BinDefinition binDef = definition.getBinDefinition(index); return new Bin(0, binDef.getStart(), binDef.getEnd()); }
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());