ValueAggregator { public Value<V> median(){ if(this.weights != null){ throw new IllegalStateException(); } int size = this.values.size(); if(size == 0){ throw new UndefinedResultException(); } return this.values.median(); } protected  ValueAggregator(Vector<V> values); protected  ValueAggregator(Vector<V> values, Vector<V> weights); protected  ValueAggregator(Vector<V> values, Vector<V> weights, Vector<V> weightedValues); void add(Number value); void add(Number value, Number weight); Value<V> average(); Value<V> weightedAverage(); Value<V> sum(); Value<V> weightedSum(); Value<V> median(); Value<V> weightedMedian();  }
@Test public void median(){ ValueAggregator<Double> aggregator = new ValueAggregator.Median<>(this.valueFactory, 3); try { aggregator.median(); fail(); } catch(UndefinedResultException ure){ } aggregator.add(4d); aggregator.add(5d); assertEquals(new DoubleValue((4d + 5d) / 2d), aggregator.median()); aggregator.add(6d); assertEquals(new DoubleValue(5d), aggregator.median()); }