Make null keys work with SortedHashMap.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4914 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2007-12-20 21:21:44 +00:00
parent c90e8ef83d
commit d70b867ddb
2 changed files with 13 additions and 2 deletions
+10 -2
View File
@@ -32,12 +32,20 @@ public class ArrayUtil
{
/**
* Sort the specified array according to natural order- all elements
* must implement Comparable.
* must implement Comparable or be null.
*/
public static function sort (arr :Array) :void
{
arr.sort(function (obj1 :Object, obj2 :Object) :int {
return Comparable(obj1).compareTo(obj2);
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);
}
});
}
@@ -88,6 +88,9 @@ public class SortedHashMap extends HashMap
protected function validateKey (key :Object) :void
// throws ArgumentError
{
if (key == null) {
return;
}
switch (_keyType) {
case COMPARABLE_KEYS:
if (key is Comparable) {