Averager extends AbstractCollectionFunction<I,I> { @Override public I compute(Collector<I> collector) { I sum = summer.compute(collector); return multiplier.divide(sum, collector.collected()); } Averager(Summer<I> theSummer, Multiply<I> theMult); @Override I compute(Collector<I> collector); @Override Collector<I> createCollector(); static final String Id; static final Averager<Integer> IntAvg; static final Averager<Long> LongAvg; static final Averager<Float> FloatAvg; static final Averager<Double> DoubleAvg; static final Averager<BigDecimal> BigDecimalAvg; static final Map<Class<?>, Function<?,?>> AveragersByType; }
@Test public void computeInts() { for (String[] test : Tests) { Integer expectedResult = Integer.parseInt(test[0]); List<Integer> nums = intsOf(test); Collector<Integer> collector = asFinalCollector(nums); Integer result = Averager.IntAvg.compute(collector); Assert.assertEquals(result, expectedResult); } }
@Test public void computeFloats() { for (String[] test : Tests) { Float expectedResult = Float.parseFloat(test[0]); List<Float> nums = floatsOf(test); Collector<Float> collector = asFinalCollector(nums); Float result = Averager.FloatAvg.compute(collector); Assert.assertEquals(result, expectedResult); } }