Source:
public void testCompute() { ArithmeticPostAggregator arithmeticPostAggregator; ExpressionPostAggregator expressionPostAggregator; CountAggregator agg = new CountAggregator("rows"); agg.aggregate(); agg.aggregate(); agg.aggregate(); Map<String, Object> metricValues = new HashMap<String, Object>(); metricValues.put(agg.getName(), agg.get()); List<PostAggregator> postAggregatorList = Lists.newArrayList( new ConstantPostAggregator( "roku", 6D ), new FieldAccessPostAggregator( "rows", "rows" ) ); for (PostAggregator postAggregator : postAggregatorList) { metricValues.put(postAggregator.getName(), postAggregator.compute(metricValues)); } arithmeticPostAggregator = new ArithmeticPostAggregator("add", "+", postAggregatorList); expressionPostAggregator = new ExpressionPostAggregator("add", "roku + rows"); Assert.assertEquals(9.0, arithmeticPostAggregator.compute(metricValues)); Assert.assertEquals(9.0, expressionPostAggregator.compute(metricValues)); arithmeticPostAggregator = new ArithmeticPostAggregator("subtract", "-", postAggregatorList); expressionPostAggregator = new ExpressionPostAggregator("add", "roku - rows"); Assert.assertEquals(3.0, arithmeticPostAggregator.compute(metricValues)); Assert.assertEquals(3.0, expressionPostAggregator.compute(metricValues)); arithmeticPostAggregator = new ArithmeticPostAggregator("multiply", "*", postAggregatorList); expressionPostAggregator = new ExpressionPostAggregator("add", "roku * rows"); Assert.assertEquals(18.0, arithmeticPostAggregator.compute(metricValues)); Assert.assertEquals(18.0, expressionPostAggregator.compute(metricValues)); arithmeticPostAggregator = new ArithmeticPostAggregator("divide", "/", postAggregatorList); expressionPostAggregator = new ExpressionPostAggregator("add", "roku / rows"); Assert.assertEquals(2.0, arithmeticPostAggregator.compute(metricValues)); Assert.assertEquals(2.0, expressionPostAggregator.compute(metricValues)); }

Target:
public void testCompute() { final String aggName = "rows"; ArithmeticPostAggregator arithmeticPostAggregator; ExpressionPostAggregator expressionPostAggregator; CountAggregator agg = new CountAggregator(); agg.aggregate(); agg.aggregate(); agg.aggregate(); Map<String, Object> metricValues = new HashMap<String, Object>(); metricValues.put(aggName, agg.get()); List<PostAggregator> postAggregatorList = Lists.newArrayList( new ConstantPostAggregator( "roku", 6D ), new FieldAccessPostAggregator( "rows", "rows" ) ); for (PostAggregator postAggregator : postAggregatorList) { metricValues.put(postAggregator.getName(), postAggregator.compute(metricValues)); } arithmeticPostAggregator = new ArithmeticPostAggregator("add", "+", postAggregatorList); expressionPostAggregator = new ExpressionPostAggregator("add", "roku + rows"); Assert.assertEquals(9.0, arithmeticPostAggregator.compute(metricValues)); Assert.assertEquals(9.0, expressionPostAggregator.compute(metricValues)); arithmeticPostAggregator = new ArithmeticPostAggregator("subtract", "-", postAggregatorList); expressionPostAggregator = new ExpressionPostAggregator("add", "roku - rows"); Assert.assertEquals(3.0, arithmeticPostAggregator.compute(metricValues)); Assert.assertEquals(3.0, expressionPostAggregator.compute(metricValues)); arithmeticPostAggregator = new ArithmeticPostAggregator("multiply", "*", postAggregatorList); expressionPostAggregator = new ExpressionPostAggregator("add", "roku * rows"); Assert.assertEquals(18.0, arithmeticPostAggregator.compute(metricValues)); Assert.assertEquals(18.0, expressionPostAggregator.compute(metricValues)); arithmeticPostAggregator = new ArithmeticPostAggregator("divide", "/", postAggregatorList); expressionPostAggregator = new ExpressionPostAggregator("add", "roku / rows"); Assert.assertEquals(2.0, arithmeticPostAggregator.compute(metricValues)); Assert.assertEquals(2.0, expressionPostAggregator.compute(metricValues)); }