From 875d4988a36cdf1d226cae3dc5c362b936077476 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Tue, 19 Feb 2008 00:40:36 +0000 Subject: [PATCH] Added Comparators.COMPARABLE. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4937 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/ArrayUtil.as | 12 +--------- src/as/com/threerings/util/Comparators.as | 27 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 src/as/com/threerings/util/Comparators.as diff --git a/src/as/com/threerings/util/ArrayUtil.as b/src/as/com/threerings/util/ArrayUtil.as index 5e153fa4e..e27ffe321 100644 --- a/src/as/com/threerings/util/ArrayUtil.as +++ b/src/as/com/threerings/util/ArrayUtil.as @@ -36,17 +36,7 @@ public class ArrayUtil */ public static function sort (arr :Array) :void { - arr.sort(function (obj1 :Object, obj2 :Object) :int { - if (obj1 == obj2) { // same object or both null - return 0; - } else if (obj1 == null) { - return -1; - } else if (obj2 == null) { - return 1; - } else { - return Comparable(obj1).compareTo(obj2); - } - }); + arr.sort(Comparators.COMPARABLE); } /** diff --git a/src/as/com/threerings/util/Comparators.as b/src/as/com/threerings/util/Comparators.as new file mode 100644 index 000000000..49d814e7d --- /dev/null +++ b/src/as/com/threerings/util/Comparators.as @@ -0,0 +1,27 @@ +// +// $Id$ + +package com.threerings.util { + +/** + * Contains sorting Comparators. + */ +public class Comparators +{ + /** + * A standard Comparator for comparing Comparable values. + */ + public static function COMPARABLE (c1 :Comparable, c2 :Comparable) :int + { + if (c1 == c2) { // same object -or- both null + return 0; + } else if (c1 == null) { + return -1; + } else if (c2 == null) { + return 1; + } else { + return c1.compareTo(c2); + } + } +} +}