added StatSet.updateStat(), which uses a StatModifier to do its business
git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@681 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<Stat>
|
||||
_container = container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a stat in this set, using the supplied StatModifier.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Stat> void updateStat (StatModifier<T> 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<Stat>
|
||||
} 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<Stat>
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user