Java Collection Mean mean(Collection dist)

Here you can find the source of mean(Collection dist)

Description

mean

License

Open Source License

Parameter

Parameter Description
dist a parameter

Declaration

public static Double mean(Collection<Double> dist) 

Method Source Code

//package com.java2s;
import java.util.Collection;

import java.util.List;

public class Main {
    /**/*from www  . jav  a  2s  . c  om*/
     * @param sums
     * @param count
     */
    public static void mean(List<Double> sums, int count) {
        if (sums != null && !sums.isEmpty()) {
            for (int i = 0; i < sums.size(); i++) {
                sums.set(i, sums.get(i) / count);
            }
        }
    }

    /**
     *
     * @param sum
     * @param count
     * @return
     */
    public static double mean(double sum, int count) {
        return count > 0 ? sum / count : null;
    }

    /**
     *
     * @param dist
     * @return
     */
    public static Double mean(Collection<Double> dist) {
        if (dist != null && !dist.isEmpty()) {
            double sum = 0d;
            int count = 0;
            for (Double val : dist) {
                if (val != null) {
                    sum += val;
                    count++;
                }
            }
            return count > 0 ? sum / count : null;
        }
        return null;
    }
}

Related

  1. getMean(final Collection collection)
  2. getVariance(Collection data, Number mean)
  3. mean(Collection coll)
  4. mean(Collection nums)
  5. mean(Collection data)
  6. mean(Collection vector)
  7. mean(final Collection values)
  8. mean(final Collection values)
  9. meanAndVariance(Collection vector)