diff --git a/src/as/com/threerings/presents/dobj/DSet.as b/src/as/com/threerings/presents/dobj/DSet.as index e3f6fbe67..84075d989 100644 --- a/src/as/com/threerings/presents/dobj/DSet.as +++ b/src/as/com/threerings/presents/dobj/DSet.as @@ -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"); + } } /** diff --git a/src/as/com/threerings/presents/dobj/DSetEntry.as b/src/as/com/threerings/presents/dobj/DSetEntry.as index ac7f14cbf..5d08d738b 100644 --- a/src/as/com/threerings/presents/dobj/DSetEntry.as +++ b/src/as/com/threerings/presents/dobj/DSetEntry.as @@ -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; } }