From ecafc0849c814b5b296fbeb4e000d87af4daca26 Mon Sep 17 00:00:00 2001 From: Tom Conkling Date: Wed, 20 Aug 2008 01:30:04 +0000 Subject: [PATCH] StatSet.addStat()/updateStat() need to know if they were called from syncStat() so that our ServerStatSet subclass that does sneaky badge-related stuff in msoy can do the right thing with regards to badge updating. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@733 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../com/threerings/stats/data/StatSet.java | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/java/com/threerings/stats/data/StatSet.java b/src/java/com/threerings/stats/data/StatSet.java index d7a3d3ce..c51f63b8 100644 --- a/src/java/com/threerings/stats/data/StatSet.java +++ b/src/java/com/threerings/stats/data/StatSet.java @@ -77,13 +77,13 @@ public class StatSet extends DSet if (stat != null) { wasModified = stat.isModified(); modifier.modify(stat); - updateStat(stat); + updateStat(stat, true); } else { @SuppressWarnings("unchecked") T nstat = (T)modifier.getType().newStat(); stat = nstat; modifier.modify(stat); - addStat(stat); + addStat(stat, true); } stat.setModified(wasModified); @@ -102,9 +102,9 @@ public class StatSet extends DSet if (stat == null) { stat = (IntStat)type.newStat(); stat.setValue(value); - addStat(stat); + addStat(stat, false); } else if (stat.setValue(value)) { - updateStat(stat); + updateStat(stat, false); } } @@ -134,9 +134,9 @@ public class StatSet extends DSet if (stat == null) { stat = (IntStat)type.newStat(); stat.increment(delta); - addStat(stat); + addStat(stat, false); } else if (stat.increment(delta)) { - updateStat(stat); + updateStat(stat, false); } } @@ -152,10 +152,10 @@ public class StatSet extends DSet if (stat == null) { stat = (IntArrayStat)type.newStat(); stat.appendValue(value); - addStat(stat); + addStat(stat, false); } else { stat.appendValue(value); - updateStat(stat); + updateStat(stat, false); } } @@ -172,9 +172,9 @@ public class StatSet extends DSet @SuppressWarnings("unchecked") SetStat nstat = (SetStat)type.newStat(); stat = nstat; stat.add(value); - addStat(stat); + addStat(stat, false); } else if (stat.add(value)) { - updateStat(stat); + updateStat(stat, false); } } @@ -190,9 +190,9 @@ public class StatSet extends DSet if (stat == null) { stat = (StringMapStat)type.newStat(); stat.increment(value, amount); - addStat(stat); + addStat(stat, false); } else if (stat.increment(value, amount)) { - updateStat(stat); + updateStat(stat, false); } } @@ -274,7 +274,14 @@ public class StatSet extends DSet add(stat); } - protected void addStat (Stat stat) + /** + * Adds the specified Stat to the set. + * + * @param syncingWithRepo should be set to true only when called from {@link #syncStat}, + * which itself is called only when a stat modification has been made to the database, + * and the in-memory StatSet needs to be updated as a result. + */ + protected void addStat (Stat stat, boolean syncingWithRepo) { if (_container != null) { _container.addToStats(stat); @@ -283,7 +290,14 @@ public class StatSet extends DSet } } - protected void updateStat (Stat stat) + /** + * Updates the specified Stat in the set. + * + * @param syncingWithRepo should be set to true only when called from {@link #syncStat}, + * which itself is called only when a stat modification has been made to the database, + * and the in-memory StatSet needs to be updated as a result. + */ + protected void updateStat (Stat stat, boolean syncingWithRepo) { if (_container != null) { _container.updateStats(stat);