canonical example by Tabnine
private Double calculateAverageGrade(Map<String, List<Integer>> gradesList, String studentName) throws Exception { return Optional.ofNullable(gradesList.get(studentName)) .map(list -> list.stream().collect(Collectors.averagingDouble(x -> x))) .orElseThrow(() -> new Exception("Student not found - " + studentName)); }
default double mean(ToDoubleFunction<T> fn){ return stream().collect(Collectors.<T>averagingDouble(fn)); } default Option<T> median(){
default double stdDeviation(ToDoubleFunction<T> fn){ Seq<T> list = stream().seq(); double avg = list.collect(Collectors.<T>averagingDouble(fn)); return Math.sqrt( list.stream().mapToDouble(fn) .map(i->i-avg) .map(i->i*i) .average() .getAsDouble()); }
default double populationVariance(ToDoubleFunction<T> fn){ Seq<T> list = stream().seq(); double avg = list.collect(Collectors.<T>averagingDouble(fn)); return (list.map(t -> fn.applyAsDouble(t)) .map(t -> t - avg) .map(t -> t * t) .sumDouble(i -> i)/(list.size())); }
default double variance(ToDoubleFunction<T> fn){ Seq<T> list = stream().seq(); double avg = list.collect(Collectors.<T>averagingDouble(fn)); return (list.map(t -> fn.applyAsDouble(t)) .map(t -> t - avg) .map(t -> t * t) .sumDouble(i -> i))/(list.size()-1); } default double populationVariance(ToDoubleFunction<T> fn){
/** * Aggregator that returns the average over all heuristic results. * * @param values heuristic results. * @return the average. */ public static double avg(final Collection<Double> values) { return values.stream().collect(Collectors.averagingDouble((d) -> d)); }
private void average(Message<JsonObject> message) { double avg = lastValues.values().stream() .collect(Collectors.averagingDouble(Double::doubleValue)); JsonObject json = new JsonObject().put("average", avg); message.reply(json); } }
@Override public double avgDouble(ToDoubleFunction<? super T> function) { return collect(Collectors.averagingDouble(function)); }
@Override public double avgDouble(ToDoubleFunction<? super T> function) { return collect(Collectors.averagingDouble(function)); }
default double mean(ToDoubleFunction<T> fn){ return stream().collect(Collectors.<T>averagingDouble(fn)); } default Option<T> median(){
private double averageOfList(List<Double> list) { return list .stream() .collect(Collectors.averagingDouble(x -> x)); }
public static double calculateAverage(List<Double> values) { return values.stream().collect(Collectors.averagingDouble(x -> x)); }
averageTemperature = this.temperatureHistory.values() .stream() .collect(Collectors.averagingDouble(value -> value));
public static double measurePerformance(TestTask task, int attemptsCount) throws Exception { List<Double> timings = new ArrayList<>(); for (int i = 0; i < attemptsCount; i++) { double time1 = Utils.getSystemTimeMilliseconds(); task.doTest(); double time2 = Utils.getSystemTimeMilliseconds(); timings.add(time2 - time1); } return timings.stream().collect(Collectors.averagingDouble(x -> x)); }
.collect(Collectors.averagingDouble(Double::doubleValue)); final double powerUsersAvg = values.stream().map(TableDTO::getPowerUsers) .collect(Collectors.averagingDouble(Double::doubleValue));
default double stdDeviation(ToDoubleFunction<T> fn){ Seq<T> list = stream().seq(); double avg = list.collect(Collectors.<T>averagingDouble(fn)); return Math.sqrt( list.stream().mapToDouble(fn) .map(i->i-avg) .map(i->i*i) .average() .getAsDouble()); }
default double variance(ToDoubleFunction<T> fn){ Seq<T> list = stream().seq(); double avg = list.collect(Collectors.<T>averagingDouble(fn)); return (list.map(t -> fn.applyAsDouble(t)) .map(t -> t - avg) .map(t -> t * t) .sumDouble(i -> i))/(list.size()-1); } default double populationVariance(ToDoubleFunction<T> fn){
default double populationVariance(ToDoubleFunction<T> fn){ Seq<T> list = stream().seq(); double avg = list.collect(Collectors.<T>averagingDouble(fn)); return (list.map(t -> fn.applyAsDouble(t)) .map(t -> t - avg) .map(t -> t * t) .sumDouble(i -> i)/(list.size())); }
assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON); assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON); assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON);
assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON); assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), 1.5 * EPSILON); assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON); assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON); assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON); assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON); assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON);