Min extends AbstractAggregator implements Aggregator { @Override public void accept(DataSetRow row, AggregationResult result) { final String minKey = row.get(groupBy); if (StringUtils.isEmpty(minKey)) { return; } double currentValue; try { currentValue = Double.parseDouble(row.get(columnId)); } catch (NumberFormatException e) { return; } if (!result.contains(minKey)) { result.put(minKey, new NumberContext(currentValue)); } NumberContext context = (NumberContext) result.get(minKey); if (currentValue < context.getValue()) { context.setValue(currentValue); } } Min(String groupBy, String columnId); @Override void accept(DataSetRow row, AggregationResult result); @Override void normalize(AggregationResult result);  }
@Test public void shouldComputeMin() { AggregationResult result = new AggregationResult(Operator.MIN); aggregator.accept(getRow("toto", "5123.4"), result); aggregator.accept(getRow("tata", "-50.2"), result); aggregator.accept(getRow("toto", "786.884"), result); aggregator.accept(getRow("tata", "-0.2"), result); aggregator.accept(getRow("toto", "41843.453"), result); aggregator.accept(getRow("toto", "0"), result); aggregator.accept(getRow("tata", "20"), result); aggregator.accept(getRow("toto", "-1"), result); aggregator.accept(getRow("toto", "8.87"), result); aggregator.accept(getRow("tata", "875"), result); aggregator.accept(getRow("toto", "-0.01"), result); aggregator.accept(getRow("tutu", "dqsfqs"), result); Assert.assertEquals(result.get("toto").getValue(), -1, 0); Assert.assertEquals(result.get("tata").getValue(), -50.2, 0); Assert.assertNull(result.get("tutu")); }