com.threerings.stats.data
Class StatSet

java.lang.Object
  extended by com.threerings.presents.dobj.DSet<Stat>
      extended by com.threerings.stats.data.StatSet
All Implemented Interfaces:
Streamable, Cloneable, Iterable<Stat>

public class StatSet
extends DSet<Stat>

A distributed set containing Stat objects.


Nested Class Summary
static interface StatSet.Container
          An interface to be implemented by an entity that wishes to be notified when the contents of a stat set change.
 
Nested classes/interfaces inherited from class com.threerings.presents.dobj.DSet
DSet.Entry
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
Streamable.Closure
 
Field Summary
protected  StatSet.Container _container
           
 
Fields inherited from class com.threerings.presents.dobj.DSet
_entries, _modCount, _size, ENTRY_COMP, INITIAL_CAPACITY
 
Constructor Summary
StatSet()
          Creates a blank stat set.
StatSet(Iterable<Stat> contents)
          Creates a stat set with the specified contents.
StatSet(Iterator<Stat> contents)
          Creates a stat set with the specified contents.
 
Method Summary
 void addQuietly(Stat stat)
          Don't call this method, it's only needed by some tricky business we do when preventing distributed object event generation for all but the bounty criteria related stats.
protected  void addStat(Stat stat, boolean syncingWithRepo)
          Adds the specified Stat to the set.
<T> void
addToSetStat(Stat.Type type, T value)
          Adds a value to a SetStat.
 void appendStat(Stat.Type type, int value)
          Appends an integer value to an IntArrayStat.
<T> boolean
containsValue(Stat.Type type, T value)
          Returns true if the specified SetStat contains the specified value, false otherwise.
 int[] getIntArrayStat(Stat.Type type)
          Returns the current value of the specified integer array statistic.
 int getIntStat(Stat.Type type)
          Returns the current value of the specified integer statistic.
 int getMapValue(Stat.Type type, String value)
          Returns the value to which the specified string is mapped in a StringMapStat or zero if the value has not been mapped.
 int getMaxIntStat(Stat.Type type)
          Returns the maximum value by which the specified integer statistic has ever been incremented.
 int getSetStatSize(Stat.Type type)
          Returns the current size of the specified SetStat statistic.
protected  Stat getStat(Stat.Type type)
          Returns the Stat of the given type, if it exists in the set, and null otherwise.
 void incrementMapStat(Stat.Type type, String value, int amount)
          Increments a string value in a StringMapStat.
 void incrementStat(Stat.Type type, int delta)
          Increments an integer statistic in this set.
 void maxStat(Stat.Type type, int value)
          Sets an integer stat to the specified value, if it exceeds our existing recorded value.
 void setContainer(StatSet.Container container)
          Wires this stat set up to a containing user object.
 void setStat(Stat.Type type, int value)
          Sets an integer statistic in this set.
<T extends Stat>
void
syncStat(StatModifier<T> modifier)
          Updates a stat in this set, using the supplied StatModifier.
protected  void updateStat(Stat stat, boolean syncingWithRepo)
          Updates the specified Stat in the set.
 
Methods inherited from class com.threerings.presents.dobj.DSet
add, asSet, clone, compare, contains, containsKey, entries, get, getWarningSize, isEmpty, iterator, newDSet, newDSet, readField__entries, readField__size, readObject, remove, removeKey, size, toArray, toArray, toString, typedClone, update, writeField__entries, writeField__size, writeObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_container

protected transient StatSet.Container _container
Constructor Detail

StatSet

public StatSet(Iterable<Stat> contents)
Creates a stat set with the specified contents.


StatSet

public StatSet(Iterator<Stat> contents)
Creates a stat set with the specified contents.


StatSet

public StatSet()
Creates a blank stat set.

Method Detail

setContainer

public void setContainer(StatSet.Container container)
Wires this stat set up to a containing user object. All subsequent modifications will be published to the container.


syncStat

public <T extends Stat> void syncStat(StatModifier<T> modifier)
Updates a stat in this set, using the supplied StatModifier. This function should only be called after a successful stat modification has been made to the StatRepository. It will increment the Stat's modCount, and won't set its dirty bit if it's not already set, to prevent the Stat from being re-written to the repo unnecessarily.


setStat

public void setStat(Stat.Type type,
                    int value)
Sets an integer statistic in this set.

Throws:
ClassCastException - thrown if the registered type of the specified stat is not an IntStat.

maxStat

public void maxStat(Stat.Type type,
                    int value)
Sets an integer stat to the specified value, if it exceeds our existing recorded value.

Throws:
ClassCastException - thrown if the registered type of the specified stat is not an IntStat.

incrementStat

public void incrementStat(Stat.Type type,
                          int delta)
Increments an integer statistic in this set.

Throws:
ClassCastException - thrown if the registered type of the specified stat is not an IntStat.

appendStat

public void appendStat(Stat.Type type,
                       int value)
Appends an integer value to an IntArrayStat.

Throws:
ClassCastException - thrown if the registered type of the specified stat is not an IntArrayStat.

addToSetStat

public <T> void addToSetStat(Stat.Type type,
                             T value)
Adds a value to a SetStat.

Throws:
ClassCastException - thrown if the registered type of the specified stat is not an SetStat parameterized on the given type.

incrementMapStat

public void incrementMapStat(Stat.Type type,
                             String value,
                             int amount)
Increments a string value in a StringMapStat.

Throws:
ClassCastException - thrown if the registered type of the specified stat is not an StringMapStat.

getIntStat

public int getIntStat(Stat.Type type)
Returns the current value of the specified integer statistic.

Throws:
ClassCastException - thrown if the registered type of the specified stat is not an IntStat.

getMaxIntStat

public int getMaxIntStat(Stat.Type type)
Returns the maximum value by which the specified integer statistic has ever been incremented.

Throws:
ClassCastException - thrown if the registered type of the specified stat is not an MaxIntStat.

getIntArrayStat

public int[] getIntArrayStat(Stat.Type type)
Returns the current value of the specified integer array statistic.

Throws:
ClassCastException - thrown if the registered type of the specified stat is not an IntArrayStat.

getSetStatSize

public int getSetStatSize(Stat.Type type)
Returns the current size of the specified SetStat statistic.

Throws:
ClassCastException - thrown if the registered type of the specified stat is not an SetStat.

containsValue

public <T> boolean containsValue(Stat.Type type,
                                 T value)
Returns true if the specified SetStat contains the specified value, false otherwise.


getMapValue

public int getMapValue(Stat.Type type,
                       String value)
Returns the value to which the specified string is mapped in a StringMapStat or zero if the value has not been mapped.


addQuietly

public void addQuietly(Stat stat)
Don't call this method, it's only needed by some tricky business we do when preventing distributed object event generation for all but the bounty criteria related stats.


addStat

protected void addStat(Stat stat,
                       boolean syncingWithRepo)
Adds the specified Stat to the set.

Parameters:
syncingWithRepo - should be set to true only when called from syncStat(com.threerings.stats.data.StatModifier), which itself is called only when a stat modification has been made to the database, and the in-memory StatSet needs to be updated as a result.

updateStat

protected void updateStat(Stat stat,
                          boolean syncingWithRepo)
Updates the specified Stat in the set.

Parameters:
syncingWithRepo - should be set to true only when called from syncStat(com.threerings.stats.data.StatModifier), which itself is called only when a stat modification has been made to the database, and the in-memory StatSet needs to be updated as a result.

getStat

protected Stat getStat(Stat.Type type)
Returns the Stat of the given type, if it exists in the set, and null otherwise.