Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: junit/runner/Sorter.java


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