com.twitter.common.util
Class Stat

java.lang.Object
  extended by com.twitter.common.util.Stat
All Implemented Interfaces:
Serializable

public class Stat
extends Object
implements Serializable

This class is designed to provide basic statistics collection. For each instance of this object statistics and be added to it then the sum, mean, std dev, min and max can be gathered at the end. To reuse this object, a clear method can be called to reset the statistics.

See Also:
Serialized Form

Constructor Summary
Stat()
           
 
Method Summary
 void addNumber(double x)
          Add a number to the statistics collector.
 void addNumber(float x)
          Add a number to the statistics collector.
 void addNumber(int x)
          Add a number to the statistics collector.
 void clear()
          Clear the statistics counters...
 double getMax()
          Get the max data element added to the statistics object so far.
 double getMean()
          Get the average or mean of data elements added to the statistics object so far.
 double getMin()
          Get the min data element added to the statistics object so far.
 long getNumberOfElements()
          Get the number of data elements added to the statistics object so far.
 double getPercent()
          Get the ratio of the sum of elements divided by the number of elements added * 100
 double getStandardDev()
          Get the standard deviation of the data elements added to the statistics object so far.
 double getSum()
          Get the sum or mean of data elements added to the statistics object so far.
 double getSumOfSq()
          Get the sum of the squares of the data elements added to the statistics object so far.
 void readFromDataInput(DataInput in)
          Read the data from the datainput so it can be used to populate the current objects state.
 void readFromDataInput(InputStream in)
          Read the data from the inputstream so it can be used to populate the current objects state.
 String toString()
          Create a string representation of the statistics collected so far.
 String toString(boolean percent)
          Create a string representation of the statistics collected so far.
 void writeToDataOutput(DataOutput out)
          Write the data to the data output object so it can be written to an other process, wire or storage median in a format that another Stats object can read.
 void writeToDataOutput(OutputStream out)
          Write the data to the output steam so it can be streamed to an other process, wire or storage median in a format that another Stats object can read.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Stat

public Stat()
Method Detail

addNumber

public void addNumber(int x)
Add a number to the statistics collector. doubles are used for all collections.

Parameters:
int - - number added to the statistics.

addNumber

public void addNumber(float x)
Add a number to the statistics collector. doubles are used for all collections.

Parameters:
float - - number added to the statistics.

addNumber

public void addNumber(double x)
Add a number to the statistics collector. doubles are used for all collections.

Parameters:
double - - number added to the statistics.

clear

public void clear()
Clear the statistics counters...

Parameters:
void -

toString

public String toString()
Create a string representation of the statistics collected so far. NOTE this is formated and may not suit all needs and thus the user should just call the needed methods to get mean, std dev, etc. and format the data as needed.

Overrides:
toString in class Object
Parameters:
void -
Returns:
String - Java string formated out put of results.

toString

public String toString(boolean percent)
Create a string representation of the statistics collected so far. The results are formated in percentage format if passed in true, otherwise the results are the same as the toString call. NOTE this is formated and may not suit all needs and thus the user should just call the needed methods to get mean, std dev, etc. and format the data as needed.

Parameters:
boolean - - Format as percentages if set to true.
Returns:
String - Java string formated out put of results.

getMax

public double getMax()
Get the max data element added to the statistics object so far.

Parameters:
void -
Returns:
double - Maximum entry added so far.

getMin

public double getMin()
Get the min data element added to the statistics object so far.

Parameters:
void -
Returns:
double - Min entry added so far.

getNumberOfElements

public long getNumberOfElements()
Get the number of data elements added to the statistics object so far.

Parameters:
void -
Returns:
double - Number of entries added so far.

getMean

public double getMean()
Get the average or mean of data elements added to the statistics object so far.

Parameters:
void -
Returns:
double - Mean of entries added so far.

getPercent

public double getPercent()
Get the ratio of the sum of elements divided by the number of elements added * 100

Parameters:
void -
Returns:
double - Percent of entries added so far.

getSum

public double getSum()
Get the sum or mean of data elements added to the statistics object so far.

Parameters:
void -
Returns:
double - Sum of entries added so far.

getSumOfSq

public double getSumOfSq()
Get the sum of the squares of the data elements added to the statistics object so far.

Parameters:
void -
Returns:
double - Sum of the squares of the entries added so far.

getStandardDev

public double getStandardDev()
Get the standard deviation of the data elements added to the statistics object so far.

Parameters:
void -
Returns:
double - Sum of the standard deviation of the entries added so far.

readFromDataInput

public void readFromDataInput(InputStream in)
                       throws IOException
Read the data from the inputstream so it can be used to populate the current objects state.

Parameters:
InputStream - - java.io.InputStream to write to.
Throws:
IOException

readFromDataInput

public void readFromDataInput(DataInput in)
                       throws IOException
Read the data from the datainput so it can be used to populate the current objects state.

Parameters:
InputStream - - java.io.InputStream to write to.
Throws:
IOException

writeToDataOutput

public void writeToDataOutput(OutputStream out)
                       throws IOException
Write the data to the output steam so it can be streamed to an other process, wire or storage median in a format that another Stats object can read.

Parameters:
OutputStream - - java.io.OutputStream to write to.
Throws:
IOException

writeToDataOutput

public void writeToDataOutput(DataOutput out)
                       throws IOException
Write the data to the data output object so it can be written to an other process, wire or storage median in a format that another Stats object can read.

Parameters:
InputStream - - java.io.InputStream to write to.
Throws:
IOException