blob: 8d9341d23949f1254a8d49a62e55a402d8e7d6b7 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001package junit.runner;
2
3import java.util.*;
4
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005/**
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 */
11public class Sorter {
Brett Chabotf1253cd2012-01-30 11:29:54 -080012 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 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037}