Class Stats

java.lang.Object
com.mckoi.util.Stats

public final class Stats extends Object
An object that is used to store and update various stats.

NOTE: This object is thread safe.

Author:
Tobias Downer
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs the object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int value, String stat_name)
    Adds the given value to a stat property.
    void
    decrement(String stat_name)
    Decrements a stat property.
    get(String stat_name)
    Retrieves the current Object value of a stat property.
    void
    increment(String stat_name)
    Increments a stat property.
    Return a String array of all stat keys sorted in order from lowest to highest.
    void
    Outputs the stats to a print stream.
    void
    Resets all stats that start with "{session}" to 0.
    void
    set(int value, String stat_name)
    Sets the given stat name with the given value.
    Returns a String representation of the stat with the given key name.
    Returns a String that can be use to print out the values of all the stats.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Stats

      public Stats()
      Constructs the object.
  • Method Details

    • resetSession

      public void resetSession()
      Resets all stats that start with "{session}" to 0. This should be called when we are collecting stats over a given session and a session has finished.
    • add

      public void add(int value, String stat_name)
      Adds the given value to a stat property.
    • increment

      public void increment(String stat_name)
      Increments a stat property. eg. stats.increment("File Hits");
    • decrement

      public void decrement(String stat_name)
      Decrements a stat property.
    • get

      public Object get(String stat_name)
      Retrieves the current Object value of a stat property. Returns null if the stat wasn't found.
    • set

      public void set(int value, String stat_name)
      Sets the given stat name with the given value.
    • keyList

      public String[] keyList()
      Return a String array of all stat keys sorted in order from lowest to highest.
    • statString

      public String statString(String key)
      Returns a String representation of the stat with the given key name.
    • toString

      public String toString()
      Returns a String that can be use to print out the values of all the stats.
      Overrides:
      toString in class Object
    • printTo

      public void printTo(PrintStream out)
      Outputs the stats to a print stream.