Create the somewhat confusingly named MaxValueIntStat -- there's already a MaxIntStat here, which tracks the maximum value that the stat has been incremented by; MaxValueIntStat tracks the maximum value that the stat has ever attained.

Maybe these two classes should be merged into one? I'm worried that might break other code that already relies on MaxIntStat. Brighter minds: please advise.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@677 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Tom Conkling
2008-07-24 21:19:20 +00:00
parent 25a657d7c6
commit 1683eab1b5
@@ -0,0 +1,58 @@
//
// $Id$
package com.threerings.stats.data;
import java.io.IOException;
import java.io.EOFException;
import com.threerings.io.ObjectInputStream;
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
* been incremented by).
*/
public class MaxValueIntStat extends IntStat
{
/**
* Returns the maximum value that this integer statistic has ever been assigned.
*/
public int getMaxValue ()
{
return _maxValue;
}
@Override // from IntStat
public boolean setValue (int value)
{
_maxValue = Math.max(value, _maxValue);
return super.setValue(value);
}
@Override // from IntStat
public String valueToString ()
{
return super.valueToString() + " " + String.valueOf(_maxValue);
}
@Override // from IntStat
public void persistTo (ObjectOutputStream out, AuxDataSource aux)
throws IOException
{
super.persistTo(out, aux);
out.writeInt(_maxValue);
}
@Override // from IntStat
public void unpersistFrom (ObjectInputStream in, AuxDataSource aux)
throws IOException, ClassNotFoundException
{
super.unpersistFrom(in, aux);
_maxValue = in.readInt();
}
/** The largest value ever accumulated to this stat. */
protected int _maxValue;
}