Java mean Mean(Object in)

Here you can find the source of Mean(Object in)

Description

Mean

License

Open Source License

Declaration

public static final double Mean(Object in) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final double Mean(Object in) {
        return ((double) Sum(in) / (double) NElem(in));
    }// www.j a  v  a 2s  .c  o  m

    public static final double Mean(Object in, int i1, int i2) {
        return ((double) Sum(in, i1, i2) / (double) (i2 - i1 + 1));
    }

    public static final int Sum(Object in, int min, int max) {
        if (in == null)
            return 0;
        // END NO BOOL
        /* BOOL ONLY
        public static final int Sum( Object in, int min, int max ) {
        // END BOOL ONLY */
        if (in instanceof int[]) {
            int[] inn = (int[]) in;
            if (max >= inn.length)
                max = inn.length - 1;
            // NO BOOL
            int out = 0;
            for (int i = min; i <= max; i++)
                out += inn[i];
            return out;
            // END NO BOOL
            /* BOOL ONLY
              int out = 0; for ( int i = min; i <= max; i ++ ) out += inn[ i ] ? 1 : 0; 
             return out; 
            // END BOOL ONLY */
        } else {
            // NO BOOL
            int out = 0;
            // END NO BOOL
            /* BOOL ONLY
              int out = 0; 
            // END BOOL ONLY */
            for (int i = 0, s = ((Object[]) in).length; i < s; i++)
                out += Sum(((Object[]) in)[i], min, max);
            return out;
        }
    }

    public static final int Sum(Object in) {
        // END NO BOOL
        /* BOOL ONLY
        public static final int Sum( Object in ) {
        // END BOOL ONLY */
        if (in instanceof int[])
            return Sum((int[]) in, 0, ((int[]) in).length);
        else {
            // NO BOOL
            int out = 0;
            // END NO BOOL
            /* BOOL ONLY
              int out = 0; 
            // END BOOL ONLY */
            for (int i = 0, s = ((Object[]) in).length; i < s; i++)
                out += Sum(((Object[]) in)[i]);
            return out;
        }
    }

    public static final int NElem(Object in) {
        if (in instanceof int[])
            return ((int[]) in).length;
        else {
            int sum = 0;
            for (int i = 0, s = ((Object[]) in).length; i < s; i++)
                sum += NElem(((Object[]) in)[i]);
            return sum;
        }
    }
}

Related

  1. mean(Integer[] values)
  2. mean(List a)
  3. mean(List values)
  4. mean(long[] values)
  5. mean(Number[] array)
  6. mean_Integer(List values)
  7. meanAbortedExecutionTime( double totalExecutionTime, int totalOps, double granuleAbortProb)
  8. meanAndStandardDeviation(final double[] inp, final int startIndex, final int pastEnd)
  9. meanAndVariance(double[] a, boolean useUnbiasedEstimate)