public static double calculateTestStatistic(double[] sample1,double[] sample2){
  double maximum=0.0;
  int index1=0, index2=0;
  double cdf1=0, cdf2=0;
  while (index1 < sample1.length && index2 < sample2.length) {
    final double x1=sample1[index1], x2=sample2[index2];
    if (x1 <= x2) {
      index1++;
      while (index1 < sample1.length && sample1[index1] == x1) {
        index1++;
      }
      cdf1=((double)index1 + 1.) / (sample1.length + 1.);
    }
    if (x1 >= x2) {
      index2++;
      while (index2 < sample2.length && sample2[index2] == x2) {
        index2++;
      }
      cdf2=((double)index2 + 1.) / (sample2.length + 1.);
    }
    maximum=Math.max(maximum,Math.abs(cdf1 - cdf2));
  }
  return maximum;
}

public static double calculateTestStatistic ( double [ ] sample1 , double [ ] sample2 ) { double maximum = 0.0 ; int index1 = 0 , index2 = 0 ; double cdf1 = 0 , cdf2 = 0 ; while ( index1 < sample1 . length && index2 < sample2 . length ) { final double x1 = sample1 [ index1 ] , x2 = sample2 [ index2 ] ; if ( x1 <= x2 ) { index1 ++ ; while ( index1 < sample1 . length && sample1 [ index1 ] == x1 ) { index1 ++ ; } cdf1 = ( ( double ) index1 + 1. ) / ( sample1 . length + 1. ) ; } if ( x1 >= x2 ) { index2 ++ ; while ( index2 < sample2 . length && sample2 [ index2 ] == x2 ) { index2 ++ ; } cdf2 = ( ( double ) index2 + 1. ) / ( sample2 . length + 1. ) ; } maximum = Math . max ( maximum , Math . abs ( cdf1 - cdf2 ) ) ; } return maximum ; }
calculates the maximum distance between the two empirical cdfs of two data samples . the sample positions and cdfs must be synchronized !
