Java List Median getGeneMedian(final List doubleArray)

Here you can find the source of getGeneMedian(final List doubleArray)

Description

get Gene Median

License

GNU General Public License

Declaration

public static double getGeneMedian(final List<Double> doubleArray) 

Method Source Code

//package com.java2s;
/*/*from w w w.j ava2  s.c  om*/
 *                      Nividic development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the microarray platform
 * of the ?cole Normale Sup?rieure and the individual authors.
 * These should be listed in @author doc comments.
 *
 * For more information on the Nividic project and its aims,
 * or to join the Nividic mailing list, visit the home page
 * at:
 *
 *      http://www.transcriptome.ens.fr/nividic
 *
 */

import java.util.Collections;
import java.util.List;

public class Main {
    public static double getGeneMedian(final List<Double> doubleArray) {

        Collections.sort(doubleArray);

        Double median;

        if (doubleArray.size() == 1)
            return doubleArray.get(0);

        int center = doubleArray.size() / 2;

        if (doubleArray.size() % 2 == 0) {

            final double a, b;

            a = doubleArray.get(center);
            b = doubleArray.get(center - 1);
            median = new Double((a + b) / 2);
        } else
            median = doubleArray.get(center);

        return median.doubleValue();
    }
}

Related

  1. calcMedian(List values, int start, int end)
  2. calculateMAD(List values, Number median)
  3. calculateMedian(List values)
  4. calculateMedian(List values, boolean copyAndSort)
  5. getMedian(Collection list)
  6. getMedian(List list)
  7. getMedian(List numbers)
  8. getMedian(List results)