Added createReverse(), and make comparators compatible with a flex Sort

object.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5691 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2009-03-24 20:56:34 +00:00
parent 904be81707
commit d46acc6bc4
+12 -1
View File
@@ -5,13 +5,14 @@ package com.threerings.util {
/**
* Contains sorting Comparators.
* These functions are suitable for passing to Array.sort(), or with a flex Sort object.
*/
public class Comparators
{
/**
* A standard Comparator for comparing Comparable values.
*/
public static function COMPARABLE (c1 :Comparable, c2 :Comparable) :int
public static function COMPARABLE (c1 :Comparable, c2 :Comparable, ... ignored) :int
{
if (c1 == c2) { // same object -or- both null
return 0;
@@ -23,5 +24,15 @@ public class Comparators
return c1.compareTo(c2);
}
}
/**
* Create a Comparator function that reverses the ordering of the specified Comparator.
*/
public static function createReverse (comparator :Function) :Function
{
return function (o1 :Object, o2 :Object, ... ignored) :int {
return comparator(o2, o1); // simply reverse the ordering
}
}
}
}