Java Utililty Methods List Median

List of utility methods to do List Median

Description

The list of methods to do List Median are organized into topic(s).

Method

doublecalcMedian(List values, int start, int end)
calc Median
double result = Double.NaN;
final int count = end - start + 1;
if (count > 0) {
    if (count % 2 == 1) {
        if (count > 1) {
            result = values.get(start + ((count - 1) / 2)).doubleValue();
        } else {
            result = values.get(start).doubleValue();
...
doublecalculateMAD(List values, Number median)
calculate MAD
double result = Double.NaN;
if (values != null && median != null) {
    final List<Double> diffs = new ArrayList<Double>(values.size());
    for (int i = 0; i < values.size(); i++) {
        diffs.add(Math.abs(values.get(i).doubleValue() - median.doubleValue()));
    Collections.sort(diffs);
    final int count = diffs.size();
...
doublecalculateMedian(List values)
Utility method to calculate the median of a given list of values.
if (values == null || values.isEmpty()) {
    throw new IllegalStateException("Can not calculate median on empty list or null!");
if (values.size() == 1) {
    return values.get(0);
double[] valueArray = toArray(values);
return calculateMedian(valueArray);
...
doublecalculateMedian(List values, boolean copyAndSort)
Calculates the median for a list of values (Number objects).
double result = Double.NaN;
if (values != null) {
    if (copyAndSort) {
        final List<Double> copy = new ArrayList<Double>(values);
        Collections.sort(copy);
        values = copy;
    result = calcMedian(values, 0, values.size() - 1);
...
doublegetGeneMedian(final List doubleArray)
get Gene Median
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);
...
doublegetMedian(Collection list)
Find the median of a Collection of Doubles.
ArrayList<Double> sortList = new ArrayList<Double>(list);
Collections.sort(sortList);
int size = list.size();
double v1 = ((Double) sortList.get((size - 1) / 2)).doubleValue();
double v2 = ((Double) sortList.get(size / 2)).doubleValue();
return (v1 + v2) / 2;
ObjectgetMedian(List list)
get Median
return orderStatisticSearch((int) Math.ceil(list.size() / 2), list);
DoublegetMedian(List numbers)
Given a list of numbers returns the median of the of the list
double median;
Collections.sort(numbers);
int size = numbers.size();
if (size % 2 != 0) {
    median = numbers.get(size / 2);
} else {
    if (size != 1) {
        median = (numbers.get(size / 2) + numbers.get((size / 2) - 1)) / 2.0;
...
doublegetMedian(List results)
get Median
Collections.sort(results);
if (results.size() % 2 == 0)
    return ((double) results.get(results.size() / 2) + (double) results.get(results.size() / 2 - 1)) / 2;
else
    return (double) results.get(results.size() / 2);
intgetMedianValue(List nums)
Gets the median value from a list of numbers.
List<Integer> copy = new ArrayList<Integer>(nums);
Collections.sort(copy);
int numberOfValues = copy.size();
if (numberOfValues % 2 == 0) {
    int val1 = copy.get(numberOfValues / 2);
    int val2 = copy.get((numberOfValues - 2) / 2);
    return (val1 + val2) / 2;
} else {
...