From 76ba2840c43a1d2918b8c7434b7e5ff0c6a931b6 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sun, 27 Oct 2002 01:33:43 +0000 Subject: [PATCH] Provide access to the values that existed previous to the application of events that change values. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1837 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/dobj/AttributeChangedEvent.java | 14 +++++++++++++- .../presents/dobj/ElementUpdatedEvent.java | 15 ++++++++++++++- .../presents/dobj/EntryUpdatedEvent.java | 14 +++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/java/com/threerings/presents/dobj/AttributeChangedEvent.java b/src/java/com/threerings/presents/dobj/AttributeChangedEvent.java index ee98596ca..102ae2b9e 100644 --- a/src/java/com/threerings/presents/dobj/AttributeChangedEvent.java +++ b/src/java/com/threerings/presents/dobj/AttributeChangedEvent.java @@ -1,5 +1,5 @@ // -// $Id: AttributeChangedEvent.java,v 1.12 2002/07/23 05:52:48 mdb Exp $ +// $Id: AttributeChangedEvent.java,v 1.13 2002/10/27 01:33:43 mdb Exp $ package com.threerings.presents.dobj; @@ -63,6 +63,15 @@ public class AttributeChangedEvent extends DEvent return _value; } + /** + * Returns the value of the attribute prior to the application of this + * event. + */ + public Object getOldValue () + { + return _oldValue; + } + /** * Returns the new value of the attribute as a short. This will fail * if the attribute in question is not a short. @@ -114,6 +123,8 @@ public class AttributeChangedEvent extends DEvent public boolean applyToObject (DObject target) throws ObjectAccessException { + // grab the previous value + _oldValue = target.getAttribute(_name); // pass the new value on to the object target.setAttribute(_name, _value); return true; @@ -161,4 +172,5 @@ public class AttributeChangedEvent extends DEvent protected String _name; protected Object _value; + protected transient Object _oldValue; } diff --git a/src/java/com/threerings/presents/dobj/ElementUpdatedEvent.java b/src/java/com/threerings/presents/dobj/ElementUpdatedEvent.java index 68fdfb350..8230479ae 100644 --- a/src/java/com/threerings/presents/dobj/ElementUpdatedEvent.java +++ b/src/java/com/threerings/presents/dobj/ElementUpdatedEvent.java @@ -1,5 +1,5 @@ // -// $Id: ElementUpdatedEvent.java,v 1.2 2002/07/23 05:52:48 mdb Exp $ +// $Id: ElementUpdatedEvent.java,v 1.3 2002/10/27 01:33:43 mdb Exp $ package com.threerings.presents.dobj; @@ -68,6 +68,15 @@ public class ElementUpdatedEvent extends DEvent return _value; } + /** + * Returns the value of the element prior to the application of this + * event. + */ + public Object getOldValue () + { + return _oldValue; + } + /** * Returns the index of the element. */ @@ -138,6 +147,9 @@ public class ElementUpdatedEvent extends DEvent throw new Exception(msg); } + // grab the previous value to provide to interested parties + _oldValue = Array.get(field.get(target), _index); + // we don't do any magical expansion or any funny business; // the array should be big enough to contain the value being // updated or we'll throw an ArrayIndexOutOfBoundsException @@ -197,4 +209,5 @@ public class ElementUpdatedEvent extends DEvent protected String _name; protected Object _value; protected int _index; + protected transient Object _oldValue; } diff --git a/src/java/com/threerings/presents/dobj/EntryUpdatedEvent.java b/src/java/com/threerings/presents/dobj/EntryUpdatedEvent.java index 2f9f2fafd..141e10021 100644 --- a/src/java/com/threerings/presents/dobj/EntryUpdatedEvent.java +++ b/src/java/com/threerings/presents/dobj/EntryUpdatedEvent.java @@ -1,5 +1,5 @@ // -// $Id: EntryUpdatedEvent.java,v 1.7 2002/07/23 05:52:48 mdb Exp $ +// $Id: EntryUpdatedEvent.java,v 1.8 2002/10/27 01:33:43 mdb Exp $ package com.threerings.presents.dobj; @@ -63,6 +63,14 @@ public class EntryUpdatedEvent extends DEvent return _entry; } + /** + * Returns the entry that was in the set prior to being updated. + */ + public DSet.Entry getOldEntry () + { + return _oldEntry; + } + /** * Applies this event to the object. */ @@ -71,6 +79,9 @@ public class EntryUpdatedEvent extends DEvent { DSet set = (DSet)target.getAttribute(_name); + // fetch the previous value for interested callers + _oldEntry = set.get(_entry.getKey()); + // update the entry if (!set.update(_entry)) { // complain if we didn't update anything @@ -124,4 +135,5 @@ public class EntryUpdatedEvent extends DEvent protected String _name; protected DSet.Entry _entry; + protected transient DSet.Entry _oldEntry; }