OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / test-runner / src / 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  * {@hide} - Not needed for 1.0 SDK
12  */
13 public class Sorter {
14         public static interface Swapper {
15                 public void swap(Vector values, int left, int right);
16         }
17                 
18         public static void sortStrings(Vector values , int left, int right, Swapper swapper) { 
19                 int oleft= left;
20                 int oright= right;
21                 String mid= (String)values.elementAt((left + right) / 2); 
22                 do { 
23                         while (((String)(values.elementAt(left))).compareTo(mid) < 0)  
24                                 left++; 
25                         while (mid.compareTo((String)(values.elementAt(right))) < 0)  
26                                 right--; 
27                         if (left <= right) {
28                                 swapper.swap(values, left, right); 
29                                 left++; 
30                                 right--; 
31                         } 
32                 } while (left <= right);
33                 
34                 if (oleft < right) 
35                         sortStrings(values, oleft, right, swapper); 
36                 if (left < oright) 
37                          sortStrings(values, left, oright, swapper); 
38         }
39 }