protected int countTies(double[] withinDistances,int[] withinTies){
  int wties=0, running=1;
  for (int i=1; i <= withinDistances.length; ++i) {
    if (i == withinDistances.length || withinDistances[i - 1] != withinDistances[i]) {
      for (int j=i - running; j < i; j++) {
        withinTies[j]=running;
      }
      wties+=running - 1;
      running=1;
    }
 else {
      running++;
    }
  }
  return wties;
}

protected int countTies ( double [ ] withinDistances , int [ ] withinTies ) { int wties = 0 , running = 1 ; for ( int i = 1 ; i <= withinDistances . length ; ++ i ) { if ( i == withinDistances . length || withinDistances [ i - 1 ] != withinDistances [ i ] ) { for ( int j = i - running ; j < i ; j ++ ) { withinTies [ j ] = running ; } wties += running - 1 ; running = 1 ; } else { running ++ ; } } return wties ; }
count ( and annotate ) the number of tied values .
