### Question:
ExpressionUtil { @SuppressWarnings ( value = {"rawtypes", "unchecked"} ) static public FieldValue evaluateAggregate(Aggregate aggregate, EvaluationContext context){ FieldValue value = evaluate(aggregate.getField(), context); Collection<?> values; try { values = (Collection<?>)FieldValueUtil.getValue(value); } catch(ClassCastException cce){ throw new TypeCheckException(Collection.class, value); } FieldName groupName = aggregate.getGroupField(); if(groupName != null){ FieldValue groupValue = evaluate(groupName, context); TypeUtil.getDataType(FieldValueUtil.getValue(groupValue)); } values = Lists.newArrayList(Iterables.filter(values, Predicates.notNull())); Aggregate.Function function = aggregate.getFunction(); switch(function){ case COUNT: return FieldValueUtil.create(values.size()); case SUM: return FunctionUtil.evaluate(new Apply("sum"), createValues(values), context); case AVERAGE: return FunctionUtil.evaluate(new Apply("avg"), createValues(values), context); case MIN: return FieldValueUtil.create(Collections.min((List<Comparable>)values)); case MAX: return FieldValueUtil.create(Collections.max((List<Comparable>)values)); default: throw new UnsupportedFeatureException(aggregate, function); } } private  ExpressionUtil(); static FieldValue evaluate(FieldName name, EvaluationContext context); static FieldValue evaluate(DerivedField derivedField, EvaluationContext context); static FieldValue evaluate(Expression expression, EvaluationContext context); static FieldValue evaluateConstant(Constant constant, EvaluationContext context); static FieldValue evaluateFieldRef(FieldRef fieldRef, EvaluationContext context); static FieldValue evaluateNormContinuous(NormContinuous normContinuous, EvaluationContext context); static FieldValue evaluateNormDiscrete(NormDiscrete normDiscrete, EvaluationContext context); static FieldValue evaluateDiscretize(Discretize discretize, EvaluationContext context); static FieldValue evaluateMapValues(MapValues mapValues, EvaluationContext context); static FieldValue evaluateApply(Apply apply, EvaluationContext context); @SuppressWarnings ( value = {"rawtypes", "unchecked"} ) static FieldValue evaluateAggregate(Aggregate aggregate, EvaluationContext context);  }### Answer:
@Test public void evaluateAggregate(){ FieldName name = new FieldName("x"); List<?> values = Arrays.asList(TypeUtil.parse(DataType.DATE, "2013-01-01"), TypeUtil.parse(DataType.DATE, "2013-02-01"), TypeUtil.parse(DataType.DATE, "2013-03-01")); EvaluationContext context = createContext(name, values); Aggregate aggregate = new Aggregate(name, Aggregate.Function.COUNT); assertEquals(3, evaluate(aggregate, context)); aggregate.setFunction(Aggregate.Function.MIN); assertEquals(values.get(0), evaluate(aggregate, context)); aggregate.setFunction(Aggregate.Function.MAX); assertEquals(values.get(2), evaluate(aggregate, context)); }