com.threerings.stats.data
Class Stat

java.lang.Object
  extended by com.threerings.stats.data.Stat
All Implemented Interfaces:
com.threerings.io.Streamable, com.threerings.presents.dobj.DSet.Entry, Cloneable
Direct Known Subclasses:
IntArrayStat, IntStat, SetStat, StringMapStat

public abstract class Stat
extends Object
implements com.threerings.presents.dobj.DSet.Entry, Cloneable

A base class for persistent statistics tracked on a per-player basis (some for a single game, others for all time).


Nested Class Summary
static interface Stat.AuxDataSource
          Provides auxilliary information to statistics during the persisting process.
static interface Stat.Type
          Defines the various per-player tracked statistics.
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
com.threerings.io.Streamable.Closure
 
Constructor Summary
Stat()
           
 
Method Summary
 Stat clone()
           
 int getCode()
          Returns the integer code to which this statistic's name maps.
 String getKey()
           
 byte getModCount()
          Returns the modification count of this Stat when it was loaded from the repository.
 Stat.Type getType()
          Returns the type of this statistic.
static Stat.Type getType(int code)
          Maps a Stat.Type's code code back to a Stat.Type instance.
static int initType(Stat.Type type, Stat prototype)
          Used by the Stat.Type implementation to map itself to an integer code.
 boolean isModified()
          Returns true if the supplied statistic has been modified since it was loaded from the repository.
abstract  void persistTo(com.threerings.io.ObjectOutputStream out, Stat.AuxDataSource aux)
          Serializes this instance for storage in the item database.
 void setModCount(byte modCount)
          Sets the modification count for this Stat.
 void setModified(boolean modified)
          Forces this stat to consider itself modified.
 String toString()
           
abstract  void unpersistFrom(com.threerings.io.ObjectInputStream in, Stat.AuxDataSource aux)
          Unserializes this item from data obtained from the item database.
abstract  String valueToString()
          Derived statistics must override this method and render their value to a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Stat

public Stat()
Method Detail

getType

public static Stat.Type getType(int code)
Maps a Stat.Type's code code back to a Stat.Type instance.


initType

public static int initType(Stat.Type type,
                           Stat prototype)
Used by the Stat.Type implementation to map itself to an integer code.

Returns:
the code to which the supplied type was mapped.

getType

public Stat.Type getType()
Returns the type of this statistic.


getCode

public int getCode()
Returns the integer code to which this statistic's name maps.


isModified

public boolean isModified()
Returns true if the supplied statistic has been modified since it was loaded from the repository.


setModified

public void setModified(boolean modified)
Forces this stat to consider itself modified. Generally this is not called but rather the derived class will update its modified state when it is actually modified.


getModCount

public byte getModCount()
Returns the modification count of this Stat when it was loaded from the repository.


setModCount

public void setModCount(byte modCount)
Sets the modification count for this Stat. StatRepository calls this when converting a StatRecord into a Stat; it shouldn't be called otherwise.


persistTo

public abstract void persistTo(com.threerings.io.ObjectOutputStream out,
                               Stat.AuxDataSource aux)
                        throws IOException
Serializes this instance for storage in the item database. Derived classes must override this method to implement persistence.

Throws:
IOException

unpersistFrom

public abstract void unpersistFrom(com.threerings.io.ObjectInputStream in,
                                   Stat.AuxDataSource aux)
                            throws IOException,
                                   ClassNotFoundException
Unserializes this item from data obtained from the item database. Derived classes must override this method to implement persistence.

Throws:
IOException
ClassNotFoundException

toString

public String toString()
Overrides:
toString in class Object

valueToString

public abstract String valueToString()
Derived statistics must override this method and render their value to a string. Used by toString() and to display the value in game.


getKey

public String getKey()
Specified by:
getKey in interface com.threerings.presents.dobj.DSet.Entry

clone

public Stat clone()
Overrides:
clone in class Object


Copyright © 2011. All Rights Reserved.