@Override public boolean equals(Object obj) { if (obj == null) return false; if (this == obj) return true; if (getClass() != obj.getClass()) return false; SparseHistogram other = (SparseHistogram) obj; return ObjectUtil.typedEquals(getHistogramDefinition(), other.getHistogramDefinition()) && ListUtil.compareCollections(getBins(), other.getBins()) ; }
@Override public int hashCode() { return ObjectUtil.hashCode(getHistogramDefinition()) + ListUtil.size(getBins()) // we do not use the hash since list order may vary ; }
public void toData(DataOutput dataOutput) throws IOException { super.toData(serialVersionUID, dataOutput); dataOutput.writeInt(slots.size()); int usedSlots = 0; for (GaugeMetricValue v : slots) { if (v != null) usedSlots++; } dataOutput.writeInt(usedSlots); int idx = -1; for (GaugeMetricValue v : slots) { idx++; if (v == null) { continue; } dataOutput.writeInt(idx); dataOutput.writeDouble(v.getMin()); dataOutput.writeDouble(v.getMax()); dataOutput.writeLong(v.getN()); dataOutput.writeDouble(v.getSum()); dataOutput.writeDouble(v.getSumOfSquares()); dataOutput.writeLong(v.getRange().getStart()); SparseHistogram histo = v.getHistogram(); dataOutput.writeInt(histo.getBins().size()); for (IndexedBin bin : histo.getBins()) { dataOutput.writeInt(bin.getBinNumber()); dataOutput.writeLong(bin.getCount()); } } }
List<IndexedBin> bins = histo.getBins(); long[] binCountLeft = new long[bins.size()]; for (int i=0; i<bins.size(); i++) {
/** * Add all data from another histogram into this accumulator. The passed * histogram must be created against the same {@link HistogramDefinition} as * any other histograms passed into this accumulator. */ public void add(SparseHistogram histo) { for (IndexedBin addBin : histo.getBins()) { MutableLong bin = getOrCreateBin(addBin.getBinNumber()); bin.increment(addBin.getCount()); } }
@Override public void serialize(SparseHistogram value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeObjectField("bins", value.getBins()); jgen.writeObjectField("histogramDefinition", value.getHistogramDefinition()); jgen.writeEndObject(); }
List<IndexedBin> populatedBins=xlatedSparse.getBins(); if (ListUtil.size(populatedBins) <= 0) { return new Histogram();