Extracted the Bang stats system into reusable land. Too late for Yohoho, but
Whirled will benefit. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@251 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// $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 a maximum value which is updated every time a value
|
||||
* is accumulated to the stat. Thus we track an accumulating value as well as the largest amount by
|
||||
* which it has ever accumulated.
|
||||
*/
|
||||
public class MaxIntStat extends IntStat
|
||||
{
|
||||
/**
|
||||
* Returns the maximum value every accumulated to this integer statistic.
|
||||
*/
|
||||
public int getMaxValue ()
|
||||
{
|
||||
return _maxValue;
|
||||
}
|
||||
|
||||
@Override // from IntStat
|
||||
public boolean increment (int delta)
|
||||
{
|
||||
if (super.increment(delta)) {
|
||||
_maxValue = Math.max(delta, _maxValue);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
Reference in New Issue
Block a user