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:
@@ -4,6 +4,8 @@ import flash.util.StringBuilder;
|
|||||||
|
|
||||||
import mx.collections.IViewCursor;
|
import mx.collections.IViewCursor;
|
||||||
|
|
||||||
|
import mx.utils.ObjectUtil;
|
||||||
|
|
||||||
import com.threerings.util.Equalable;
|
import com.threerings.util.Equalable;
|
||||||
|
|
||||||
import com.threerings.io.ObjectInputStream;
|
import com.threerings.io.ObjectInputStream;
|
||||||
@@ -150,7 +152,14 @@ public class DSet
|
|||||||
*/
|
*/
|
||||||
internal function add (elem :DSetEntry) :Boolean
|
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 +
|
Log.warning("Refusing to add duplicate entry [set=" + this +
|
||||||
", entry=" + elem + "].");
|
", entry=" + elem + "].");
|
||||||
return false;
|
return false;
|
||||||
@@ -225,8 +234,15 @@ public class DSet
|
|||||||
*/
|
*/
|
||||||
private function isSameKey (key :Object, otherKey :Object) :Boolean
|
private function isSameKey (key :Object, otherKey :Object) :Boolean
|
||||||
{
|
{
|
||||||
return (key is Equalable) ? (key as Equalable).equals(otherKey)
|
if (ObjectUtil.isSimple(key)) {
|
||||||
: (key === otherKey);
|
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 {
|
package com.threerings.presents.dobj {
|
||||||
|
|
||||||
|
import com.threerings.util.Equalable;
|
||||||
|
|
||||||
import com.threerings.io.Streamable;
|
import com.threerings.io.Streamable;
|
||||||
|
|
||||||
public interface DSetEntry extends 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;
|
function getKey () :Object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user