private double median(List<Double> w){
  if (w.size() == 1) {
    return w.get(0);
  }
  List<Double> window=new ArrayList<Double>(w.size());
  for (  Double v : w) {
    if (!MathUtils.isCalculatable(v)) {
      return Double.NaN;
    }
    window.add(v);
  }
  int medianIndex=MathUtils.randomizedSelect(window,0,window.size() - 1,window.size() / 2);
  double median=window.get(medianIndex);
  if ((window.size() & 1) == 0) {
    int medianUpperIndex=MathUtils.randomizedSelect(window,0,window.size() - 1,window.size() / 2 + 1);
    double medianUpper=window.get(medianUpperIndex);
    median=(median + medianUpper) / 2.0;
  }
  return median;
}

private double median ( List < Double > w ) { if ( w . size ( ) == 1 ) { return w . get ( 0 ) ; } List < Double > window = new ArrayList < Double > ( w . size ( ) ) ; for ( Double v : w ) { if ( ! MathUtils . isCalculatable ( v ) ) { return Double . NaN ; } window . add ( v ) ; } int medianIndex = MathUtils . randomizedSelect ( window , 0 , window . size ( ) - 1 , window . size ( ) / 2 ) ; double median = window . get ( medianIndex ) ; if ( ( window . size ( ) & 1 ) == 0 ) { int medianUpperIndex = MathUtils . randomizedSelect ( window , 0 , window . size ( ) - 1 , window . size ( ) / 2 + 1 ) ; double medianUpper = window . get ( medianUpperIndex ) ; median = ( median + medianUpper ) / 2.0 ; } return median ; }
calculates the median for the specified values in the window .
