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