Fixed a bug: the 'old value' of some events were not getting set

because the oldValue variable didn't contain UNSET_OLD_VALUE, but
rather null because it was set that way in the constructor.
Additionally, some of the constructors would only set the old value
if it wasn't null, which is also wrong because an old value can
easily be null.

We could probably just rip apart most of this code, because for
the most part events are not constructed on the client anyway. We might be
able to get away with just making all the event constructors 0 arg, and
then we don't have to worry about UNSET_OLD_VALUE, we just always apply.
But let's try to be more similar to the Java code, and so now I emulate
multiple constructors by checking how many arguments were provided and
not configuring event-specific data if it wasn't actually provided
to the constructor.

Note: none of this would be necessary if we could just declare a constructor:

public function AttributeChangedEvent (
    targetOid :int = 0, name :String = null, value :Object = null,
    oldValue :Object = UNSET_OLD_VALUE);

But you can't use constants as the default value in a parameter list
(commence being boggled) so we have to use null instead of UNSET_OLD_VALUE
as the default value, and then check the 'arguments' special variable to
see if someone passed in null or whether it came from the default value. Aiya.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4726 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2007-06-04 22:00:48 +00:00
parent 5f0ffa11d4
commit e7379cd41a
12 changed files with 68 additions and 22 deletions
@@ -90,8 +90,12 @@ public class AttributeChangedEvent extends NamedEvent
oldValue :Object = null)
{
super(targetOid, name);
_value = value;
_oldValue = oldValue;
// only init these values if they were specified
if (arguments.length > 0) {
_value = value;
_oldValue = oldValue;
}
}
// documentation inherited
@@ -56,11 +56,13 @@ public class ElementUpdatedEvent extends NamedEvent
oldValue :Object = null, index :int = 0)
{
super(targetOid, name);
_value = value;
if (oldValue != null) {
// only init these values if they were specified
if (arguments.length > 0) {
_value = value;
_oldValue = oldValue;
_index = index;
}
_index = index;
}
/**
@@ -49,7 +49,11 @@ public class EntryAddedEvent extends NamedEvent
targetOid :int = 0, name :String = null, entry :DSet_Entry = null)
{
super(targetOid, name);
_entry = entry;
// only init these values if they were specified
if (arguments.length > 0) {
_entry = entry;
}
}
/**
@@ -53,8 +53,10 @@ public class EntryRemovedEvent extends NamedEvent
oldEntry :DSet_Entry = null)
{
super(targetOid, name);
_key = key;
if (oldEntry != null) {
// only init these values if they were specified
if (arguments.length > 0) {
_key = key;
_oldEntry = oldEntry;
}
}
@@ -51,8 +51,10 @@ public class EntryUpdatedEvent extends NamedEvent
oldEntry :DSet_Entry = null)
{
super(targetOid, name);
_entry = entry;
if (oldEntry != null) {
// only init these values if they were specified
if (arguments.length > 0) {
_entry = entry;
_oldEntry = oldEntry;
}
}
@@ -53,9 +53,13 @@ public class InvocationNotificationEvent extends DEvent
args :Array = null)
{
super(targetOid);
_receiverId = receiverId;
_methodId = methodId;
_args = args;
// only init these values if they were specified
if (arguments.length > 0) {
_receiverId = receiverId;
_methodId = methodId;
_args = args;
}
}
/**
@@ -49,9 +49,13 @@ public class InvocationRequestEvent extends DEvent
args :Array = null)
{
super(targetOid);
_invCode = invCode;
_methodId = methodId;
_args = args;
// only init these values if they were specified
if (arguments.length > 0) {
_invCode = invCode;
_methodId = methodId;
_args = args;
}
}
/**
@@ -49,9 +49,13 @@ public class InvocationResponseEvent extends DEvent
args :Array = null)
{
super(targetOid);
_requestId = requestId;
_methodId = methodId;
_args = args;
// only init these values if they were specified
if (arguments.length > 0) {
_requestId = requestId;
_methodId = methodId;
_args = args;
}
}
/**
@@ -53,7 +53,11 @@ public class MessageEvent extends NamedEvent
targetOid :int = 0, name :String = null, args :Array = null)
{
super(targetOid, name);
_args = args;
// only init these values if they were specified
if (arguments.length > 0) {
_args = args;
}
}
/**
@@ -50,7 +50,11 @@ public class ObjectAddedEvent extends NamedEvent
targetOid :int = 0, name :String = null, oid :int = 0)
{
super(targetOid, name);
_oid = oid;
// only init these values if they were specified
if (arguments.length > 0) {
_oid = oid;
}
}
/**
@@ -52,7 +52,11 @@ public class ObjectRemovedEvent extends NamedEvent
targetOid :int = 0, name :String = null, oid :int = 0)
{
super(targetOid, name);
_oid = oid;
// only init these values if they were specified
if (arguments.length > 0) {
_oid = oid;
}
}
/**
@@ -104,6 +104,14 @@ public class OidList
return _oids[index];
}
/**
* Return a new array containing all the oids in this list.
*/
public function toArray () :Array
{
return _oids.concat();
}
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
{