diff --git a/src/java/com/threerings/stats/data/MaxValueIntStat.java b/src/java/com/threerings/stats/data/MaxValueIntStat.java index 4fbc3f3e..be3fa3ef 100644 --- a/src/java/com/threerings/stats/data/MaxValueIntStat.java +++ b/src/java/com/threerings/stats/data/MaxValueIntStat.java @@ -11,7 +11,7 @@ import com.threerings.io.ObjectOutputStream; /** * Extends the {@link IntStat} by maintaining the maximum value that the stat has ever been - * assigned (unlike {@link MaxIntStat}, which tracks the maximum value that the stat has ever + * assigned (unlike {@link MaxIntStat}, which tracks the maximum value that the stat has ever * been incremented by). */ public class MaxValueIntStat extends IntStat @@ -23,7 +23,7 @@ public class MaxValueIntStat extends IntStat { return _maxValue; } - + @Override // from IntStat public boolean setValue (int value) { @@ -53,6 +53,6 @@ public class MaxValueIntStat extends IntStat _maxValue = in.readInt(); } - /** The largest value ever accumulated to this stat. */ + /** The largest value that this stat has been assigned. */ protected int _maxValue; } diff --git a/src/java/com/threerings/stats/data/StatSet.java b/src/java/com/threerings/stats/data/StatSet.java index 61fdb3c0..7f648238 100644 --- a/src/java/com/threerings/stats/data/StatSet.java +++ b/src/java/com/threerings/stats/data/StatSet.java @@ -5,6 +5,7 @@ package com.threerings.stats.data; import java.util.Iterator; +import com.threerings.media.Log; import com.threerings.presents.dobj.DSet; /** @@ -40,6 +41,24 @@ public final class StatSet extends DSet _container = container; } + /** + * Updates a stat in this set, using the supplied StatModifier. + */ + @SuppressWarnings("unchecked") + public void updateStat (StatModifier modifier) + { + Stat stat = getStat(modifier.getType()); + if (stat != null) { + modifier.modify((T)stat); + updateStat(stat); + + } else { + stat = modifier.getType().newStat(); + modifier.modify((T)stat); + addStat(stat); + } + } + /** * Sets an integer statistic in this set. * @@ -227,6 +246,8 @@ public final class StatSet extends DSet } else { add(stat); } + + Log.log.info("StatSet.addStat()", "Stat", stat); } protected void updateStat (Stat stat) @@ -234,6 +255,17 @@ public final class StatSet extends DSet if (_container != null) { _container.updateStats(stat); } + + Log.log.info("StatSet.updateStat()", "Stat", stat); + } + + /** + * Returns the Stat of the given type, if it exists in the set, and null otherwise. + */ + protected Stat getStat (Stat.Type type) + { + Stat stat = get(type.name()); + return (stat != null ? stat : null); } protected transient Container _container;