Home | History | Annotate | Download | only in runner
      1 package junit.runner;
      2 
      3 import java.util.*;
      4 
      5 /**
      6  * A custom quick sort with support to customize the swap behaviour.
      7  * NOTICE: We can't use the the sorting support from the JDK 1.2 collection
      8  * classes because of the JDK 1.1.7 compatibility.
      9  * {@hide} - Not needed for 1.0 SDK
     10  */
     11 public class Sorter {
     12     public static interface Swapper {
     13         public void swap(Vector values, int left, int right);
     14     }
     15 
     16     public static void sortStrings(Vector values , int left, int right, Swapper swapper) {
     17         int oleft= left;
     18         int oright= right;
     19         String mid= (String)values.elementAt((left + right) / 2);
     20         do {
     21             while (((String)(values.elementAt(left))).compareTo(mid) < 0)
     22                 left++;
     23             while (mid.compareTo((String)(values.elementAt(right))) < 0)
     24                 right--;
     25             if (left <= right) {
     26                 swapper.swap(values, left, right);
     27                 left++;
     28                 right--;
     29             }
     30         } while (left <= right);
     31 
     32         if (oleft < right)
     33             sortStrings(values, oleft, right, swapper);
     34         if (left < oright)
     35             sortStrings(values, left, oright, swapper);
     36     }
     37 }
     38