AvgDistinctPRQueryNode extends SumDistinctPRQueryNode { @Override public Object terminate() { double sum = ((Number) super.terminate()).doubleValue(); double result = sum / this.distinct.size(); return downCast(result); }  @Override Object terminate();  }
@Test public void terminateShouldCorrectlyComputeAverageUponDistinctAccumulatedValues() { distinctAggregator.accumulate(new HashSet<>()); distinctAggregator.accumulate(new HashSet<>(Arrays.asList(5, 6, 3, 4))); distinctAggregator.accumulate(new HashSet<>(Arrays.asList(3, 7, 8, 4))); Object result = distinctAggregator.terminate(); assertThat(result).isInstanceOf(Number.class); assertThat(((Number) result).floatValue()).isEqualTo((3 + 4 + 5 + 6 + 7 + 8) / 6.0f); }