Added a sort() method that operates on arrays of Comparable elements.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4273 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-07-18 02:22:24 +00:00
parent 786a8ab947
commit 0387014af8
+19
View File
@@ -5,6 +5,25 @@ package com.threerings.util {
*/
public class ArrayUtil
{
/**
* Sort the specified array according to natural order- all elements
* must implement Comparable.
*/
public static function sort (arr :Array) :void
{
// ensure every item is Comparable
if (!arr.every(function (item :*, index :int, array :Array) :Boolean
{
return (item is Comparable);
})) {
throw new Error("Not all elements are Comparable instances.");
}
arr.sort(function (obj1 :Object, obj2 :Object) :int {
return (obj1 as Comparable).compareTo(obj2);
});
}
/**
* Remove the first instance of the specified element from the array.
*/