From 1683eab1b53beac5193728ff59646b2d7cd22664 Mon Sep 17 00:00:00 2001 From: Tom Conkling Date: Thu, 24 Jul 2008 21:19:20 +0000 Subject: [PATCH] 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 --- .../stats/data/MaxValueIntStat.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/java/com/threerings/stats/data/MaxValueIntStat.java diff --git a/src/java/com/threerings/stats/data/MaxValueIntStat.java b/src/java/com/threerings/stats/data/MaxValueIntStat.java new file mode 100644 index 00000000..4fbc3f3e --- /dev/null +++ b/src/java/com/threerings/stats/data/MaxValueIntStat.java @@ -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; +}