VarianceAccumulator implements Serializable { VarianceAccumulator combineWith(VarianceAccumulator otherVariance) { if (EMPTY.equals(this)) { return otherVariance; } if (EMPTY.equals(otherVariance)) { return this; } BigDecimal increment = calculateIncrement(this, otherVariance); BigDecimal combinedVariance = this.variance().add(otherVariance.variance()).add(increment); return newVarianceAccumulator( combinedVariance, this.count().add(otherVariance.count()), this.sum().add(otherVariance.sum())); }    }
@Test public void testCombinesEmptyWithEmpty() { VarianceAccumulator result = VarianceAccumulator.EMPTY.combineWith(VarianceAccumulator.EMPTY); assertEquals(VarianceAccumulator.EMPTY, result); }