• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package junit.runner;
2 
3 import java.util.Vector;
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  */
10 public class Sorter {
11 	public static interface Swapper {
swap(Vector values, int left, int right)12 		public void swap(Vector values, int left, int right);
13 	}
14 
sortStrings(Vector values , int left, int right, Swapper swapper)15 	public static void sortStrings(Vector values , int left, int right, Swapper swapper) {
16 		int oleft= left;
17 		int oright= right;
18 		String mid= (String)values.elementAt((left + right) / 2);
19 		do {
20 			while (((String)(values.elementAt(left))).compareTo(mid) < 0)
21 				left++;
22 			while (mid.compareTo((String)(values.elementAt(right))) < 0)
23 				right--;
24 			if (left <= right) {
25 				swapper.swap(values, left, right);
26 				left++;
27 				right--;
28 			}
29 		} while (left <= right);
30 
31 		if (oleft < right)
32 			sortStrings(values, oleft, right, swapper);
33 		if (left < oright)
34 			 sortStrings(values, left, oright, swapper);
35 	}
36 }