From e02fb89cb01f24647e7510cb5fb25b95ab497c0d Mon Sep 17 00:00:00 2001 From: "ray.j.greenwell" Date: Wed, 26 Jan 2011 20:36:37 +0000 Subject: [PATCH] PECS, and use Collections.reverseOrder(). There are actually 5 different implementations of quicksort in here when one will do (the array versions could go away and call the list version, wrapping in Arrays.asList()). But I won't touch those right now. I am super tempted to reduce things down to one List version and one array version. Also it's weird that there are customized Comparators that are null-safe. I believe I was the one who added them in the past, but I've since learned. It's a strange undocumented "convenience" when it's easy enough for someone to provide a null-safe comparator for comparables. (In guava you can call Ordering.natural().nullsLast()). git-svn-id: https://samskivert.googlecode.com/svn/trunk@2988 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/main/java/com/samskivert/util/QuickSort.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/samskivert/util/QuickSort.java b/src/main/java/com/samskivert/util/QuickSort.java index 6103d8e8..031979e2 100644 --- a/src/main/java/com/samskivert/util/QuickSort.java +++ b/src/main/java/com/samskivert/util/QuickSort.java @@ -20,6 +20,7 @@ package com.samskivert.util; +import java.util.Collections; import java.util.List; import java.util.Comparator; @@ -337,7 +338,7 @@ public class QuickSort * Sort the elements in the specified List according to the ordering imposed by the specified * Comparator. */ - public static void sort (List a, Comparator comp) + public static void sort (List a, Comparator comp) { sort(a, 0, a.size() - 1, comp); } @@ -365,20 +366,16 @@ public class QuickSort * Sort the elements in the specified List according to the reverse ordering imposed by the * specified Comparator. */ - public static void rsort (List a, final Comparator comp) + public static void rsort (List a, Comparator comp) { - sort(a, new Comparator() { - public int compare (T o1, T o2) { - return comp.compare(o2, o1); - } - }); + sort(a, Collections.reverseOrder(comp)); } /** * Sort a subset of the elements in the specified List according to the ordering imposed by the * specified Comparator. */ - public static void sort (List a, int lo0, int hi0, Comparator comp) + public static void sort (List a, int lo0, int hi0, Comparator comp) { // bail out if we're already done if (hi0 <= lo0) {