Sum extends AbstractAggregator implements Aggregator { @Override public void accept(DataSetRow row, AggregationResult result) { final String sumKey = row.get(groupBy); if (StringUtils.isEmpty(sumKey)) { return; } double toAdd; try { toAdd = Double.parseDouble(row.get(columnId)); } catch (NumberFormatException e) { return; } if (!result.contains(sumKey)) { result.put(sumKey, new NumberContext(0d)); } NumberContext context = (NumberContext) result.get(sumKey); context.setValue(context.getValue() + toAdd); } Sum(String groupBy, String columnId); @Override void accept(DataSetRow row, AggregationResult result); @Override void normalize(AggregationResult result);  }
@Test public void shouldComputeSum() { AggregationResult result = new AggregationResult(Operator.SUM); aggregator.accept(getRow("toto", "514.3"), result); aggregator.accept(getRow("toto", "0"), result); aggregator.accept(getRow("toto", ""), result); aggregator.accept(getRow("toto", "-786.25"), result); aggregator.accept(getRow("toto", "235874"), result); aggregator.accept(getRow("toto", "-8760"), result); Assert.assertEquals(result.get("toto").getValue(), 226842.05, 0); }