Generate errors if an element's key is not simple or Equalable.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3898 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-03-01 19:52:27 +00:00
parent 703b309108
commit 2ca83d0a29
2 changed files with 26 additions and 3 deletions
+19 -3
View File
@@ -4,6 +4,8 @@ import flash.util.StringBuilder;
import mx.collections.IViewCursor;
import mx.utils.ObjectUtil;
import com.threerings.util.Equalable;
import com.threerings.io.ObjectInputStream;
@@ -150,7 +152,14 @@ public class DSet
*/
internal function add (elem :DSetEntry) :Boolean
{
if (contains(elem)) {
if (_entries.length == 0) {
// there is nothing in the map yet, check the key validity
var key :Object = elem.getKey();
if (!(key is Equalable) && !ObjectUtil.isSimple(key)) {
throw new Error("Element key is not 'simple' or Equalable");
}
} else if (contains(elem)) {
Log.warning("Refusing to add duplicate entry [set=" + this +
", entry=" + elem + "].");
return false;
@@ -225,8 +234,15 @@ public class DSet
*/
private function isSameKey (key :Object, otherKey :Object) :Boolean
{
return (key is Equalable) ? (key as Equalable).equals(otherKey)
: (key === otherKey);
if (ObjectUtil.isSimple(key)) {
return (key === otherKey);
} else if (key is Equalable) {
return (key as Equalable).equals(otherKey);
} else {
throw new Error("Element key is neither simple or Equalabe");
}
}
/**
@@ -1,9 +1,16 @@
package com.threerings.presents.dobj {
import com.threerings.util.Equalable;
import com.threerings.io.Streamable;
public interface DSetEntry extends Streamable
{
/**
* Get the key used to identify this object. On the java side of things,
* this key should be a Comparable object, but here in ActionScript land
* it needs to be either a simple type or implement Equalable.
*/
function getKey () :Object;
}
}