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:
@@ -32,12 +32,20 @@ public class ArrayUtil
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Sort the specified array according to natural order- all elements
|
* 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
|
public static function sort (arr :Array) :void
|
||||||
{
|
{
|
||||||
arr.sort(function (obj1 :Object, obj2 :Object) :int {
|
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
|
protected function validateKey (key :Object) :void
|
||||||
// throws ArgumentError
|
// throws ArgumentError
|
||||||
{
|
{
|
||||||
|
if (key == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (_keyType) {
|
switch (_keyType) {
|
||||||
case COMPARABLE_KEYS:
|
case COMPARABLE_KEYS:
|
||||||
if (key is Comparable) {
|
if (key is Comparable) {
|
||||||
|
|||||||
Reference in New Issue
Block a user