Decided to switch to using setOld{Entry|Value} instead of having two

constructors. Fixed ElementUpdatedEvent along the way.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6590 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2011-04-02 23:25:10 +00:00
parent 03576f00ee
commit 8c740b8353
5 changed files with 43 additions and 41 deletions
@@ -44,19 +44,10 @@ public class AttributeChangedEvent extends NamedEvent
* @param value the new value of the attribute (in the case of primitive types, the
* reflection-defined object-alternative is used).
*/
public AttributeChangedEvent (int targetOid, String name, Object value, Object oldValue)
public AttributeChangedEvent (int targetOid, String name, Object value)
{
super(targetOid, name);
_value = value;
_oldValue = oldValue;
}
/** For unserialization. */
public AttributeChangedEvent ()
{
super(0, null);
// we can't allow our primary ctor to be called during unserialization, or it will wipe out
// the hackery we do with _oldValue
}
/**
@@ -182,6 +173,12 @@ public class AttributeChangedEvent extends NamedEvent
StringUtil.toString(buf, _value);
}
protected AttributeChangedEvent setOldValue (Object oldValue)
{
_oldValue = oldValue;
return this;
}
protected Object _value;
protected transient Object _oldValue = UNSET_OLD_VALUE;
}
@@ -871,7 +871,8 @@ public class DObject
String name, Object value, Object oldValue, Transport transport)
{
// dispatch an attribute changed event
postEvent(new AttributeChangedEvent(_oid, name, value, oldValue).setTransport(transport));
postEvent(new AttributeChangedEvent(_oid, name, value).
setOldValue(oldValue).setTransport(transport));
}
/**
@@ -889,8 +890,8 @@ public class DObject
String name, int index, Object value, Object oldValue, Transport transport)
{
// dispatch an attribute changed event
postEvent(new ElementUpdatedEvent(_oid, name, value, oldValue, index).
setTransport(transport));
postEvent(new ElementUpdatedEvent(_oid, name, value, index).
setOldValue(oldValue).setTransport(transport));
}
/**
@@ -962,7 +963,7 @@ public class DObject
}
}
// dispatch an entry removed event
postEvent(new EntryRemovedEvent<T>(_oid, name, key, oldEntry));
postEvent(new EntryRemovedEvent<T>(_oid, name, key).setOldEntry(oldEntry));
}
/**
@@ -989,7 +990,8 @@ public class DObject
}
}
// dispatch an entry updated event
postEvent(new EntryUpdatedEvent<T>(_oid, name, entry, oldEntry).setTransport(transport));
postEvent(new EntryUpdatedEvent<T>(_oid, name, entry).
setOldEntry(oldEntry).setTransport(transport));
}
protected boolean isAuthoritative ()
@@ -43,18 +43,23 @@ public class ElementUpdatedEvent extends NamedEvent
* @param name the name of the attribute (data member) for which an element has changed.
* @param value the new value of the element (in the case of primitive types, the
* reflection-defined object-alternative is used).
* @param ovalue the previous value of the element (in the case of primitive types, the
* reflection-defined object-alternative is used).
* @param index the index in the array of the updated element.
*/
public ElementUpdatedEvent (int targetOid, String name, Object value, Object ovalue, int index)
public ElementUpdatedEvent (int targetOid, String name, Object value, int index)
{
super(targetOid, name);
_value = value;
_oldValue = ovalue;
_index = index;
}
/** For unserialization. */
public ElementUpdatedEvent ()
{
super(0, null);
// we can't allow our primary ctor to be called during unserialization, or it will wipe out
// the hackery we do with _oldValue
}
/**
* Returns the new value of the element.
*/
@@ -180,6 +185,12 @@ public class ElementUpdatedEvent extends NamedEvent
buf.append(", index=").append(_index);
}
protected ElementUpdatedEvent setOldValue (Object oldValue)
{
_oldValue = oldValue;
return this;
}
protected Object _value;
protected int _index;
protected transient Object _oldValue = UNSET_OLD_VALUE;
@@ -42,21 +42,11 @@ public class EntryRemovedEvent<T extends DSet.Entry> extends EntryEvent<T>
* @param targetOid the object id of the object from whose set we will remove an entry.
* @param name the name of the attribute from which to remove the specified entry.
* @param key the entry key that identifies the entry to remove.
* @param oldEntry the previous value of the entry.
*/
public EntryRemovedEvent (int targetOid, String name, Comparable<?> key, T oldEntry)
public EntryRemovedEvent (int targetOid, String name, Comparable<?> key)
{
super(targetOid, name);
_key = key;
_oldEntry = oldEntry;
}
/** For unserialization. */
public EntryRemovedEvent ()
{
super(0, null);
// we can't allow our primary ctor to be called during unserialization, or it will wipe out
// the hackery we do with _oldEntry
}
@Override
@@ -125,6 +115,12 @@ public class EntryRemovedEvent<T extends DSet.Entry> extends EntryEvent<T>
buf.append(", key=").append(_key);
}
protected EntryRemovedEvent setOldEntry (T oldEntry)
{
_oldEntry = oldEntry;
return this;
}
protected Comparable<?> _key;
@SuppressWarnings("unchecked")
@@ -43,21 +43,11 @@ public class EntryUpdatedEvent<T extends DSet.Entry> extends EntryEvent<T>
* @param targetOid the object id of the object to whose set we will add an entry.
* @param name the name of the attribute in which to update the specified entry.
* @param entry the entry to update.
* @param oldEntry the previous value of the entry.
*/
public EntryUpdatedEvent (int targetOid, String name, T entry, T oldEntry)
public EntryUpdatedEvent (int targetOid, String name, T entry)
{
super(targetOid, name);
_entry = entry;
_oldEntry = oldEntry;
}
/** For unserialization. */
public EntryUpdatedEvent ()
{
super(0, null);
// we can't allow our primary ctor to be called during unserialization, or it will wipe out
// the hackery we do with _oldEntry
}
@Override
@@ -128,6 +118,12 @@ public class EntryUpdatedEvent<T extends DSet.Entry> extends EntryEvent<T>
StringUtil.toString(buf, _entry);
}
protected EntryUpdatedEvent setOldEntry (T oldEntry)
{
_oldEntry = oldEntry;
return this;
}
protected T _entry;
@SuppressWarnings("unchecked")