The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 { |
Brett Chabot | f1253cd | 2012-01-30 11:29:54 -0800 | [diff] [blame] | 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 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | } |