public <T extends Average> T merge(T other) { if(other.count() == 0) return (T)this; super.merge(other); if(other instanceof AverageMinMax) { AverageMinMax o=(AverageMinMax)other; this.min=Math.min(min, o.min()); this.max=Math.max(max, o.max()); if(this.values != null) this.values.addAll(o.values); } return (T)this; }
/** Merges this average with another one */ public <T extends Average> T merge(T other) { if(Util.productGreaterThan(count, (long)Math.ceil(avg), Long.MAX_VALUE) || Util.productGreaterThan(other.count(), (long)Math.ceil(other.average()), Long.MAX_VALUE)) { // the above computation is not correct as the sum of the 2 products can still lead to overflow // a non-weighted avg avg=avg + other.average() / 2.0; } else { // compute the new average weighted by count long total_count=count + other.count(); avg=(count * avg + other.count() * other.average()) / total_count; count=total_count/2; } return (T)this; }
/** Merges this average with another one */ public <T extends Average> T merge(T other) { if(Util.productGreaterThan(count, (long)Math.ceil(avg), Long.MAX_VALUE) || Util.productGreaterThan(other.count(), (long)Math.ceil(other.average()), Long.MAX_VALUE)) { // the above computation is not correct as the sum of the 2 products can still lead to overflow // a non-weighted avg avg=avg + other.average() / 2.0; } else { // compute the new average weighted by count long total_count=count + other.count(); avg=(count * avg + other.count() * other.average()) / total_count; count=total_count/2; } return (T)this; }
public <T extends Average> T merge(T other) { if(other.count() == 0) return (T)this; super.merge(other); if(other instanceof AverageMinMax) { AverageMinMax o=(AverageMinMax)other; this.min=Math.min(min, o.min()); this.max=Math.max(max, o.max()); if(this.values != null) this.values.addAll(o.values); } return (T)this; }