NewComponentStatisticsAggregator implements Serializable { NewComponentStatisticsAggregator plus(NewComponentStatisticsAggregator other) { return new NewComponentStatisticsAggregator( totalRowCount + other.totalRowCount, rowCountForNewCluster + other.rowCountForNewCluster, sumOfAnomalies.plus(other.sumOfAnomalies) ); } NewComponentStatisticsAggregator(long totalRowCount, long rowCountForNewCluster, Vector sumOfAnomalies);  NewComponentStatisticsAggregator(); Vector mean(); long rowCountForNewCluster(); long totalRowCount();  }
@Test public void testPlus() { NewComponentStatisticsAggregator agg1 = new NewComponentStatisticsAggregator(); NewComponentStatisticsAggregator agg2 = new NewComponentStatisticsAggregator(); int rowCount = 10; for (int i = 0; i < rowCount; i++) agg1.add(VectorUtils.of(0, 1, 2), i % 2 == 0); for (int i = 0; i < rowCount; i++) agg2.add(VectorUtils.of(2, 1, 0), i % 2 == 1); NewComponentStatisticsAggregator sum = agg1.plus(agg2); assertEquals(rowCount, sum.rowCountForNewCluster()); assertEquals(rowCount * 2, sum.totalRowCount()); assertArrayEquals(new double[] {1, 1, 1}, sum.mean().asArray(), 1e-4); }