public abstract class AbstractSimpleStats extends java.lang.Object implements SampleStatistics, java.lang.Cloneable
This class contains a skeletal implementation for collecting new observations that tracks the minimum and maximum values, along with the number of observations. Classes extending AbstractSimpleStatistics will need to implement the logic for calculating the mean and standard deviation.
Modifier and Type | Field and Description |
---|---|
protected int |
count
The total number of observations recorded.
|
protected static java.lang.String |
DEFAULT_NAME
The default name for SampleStatistics.
|
static java.text.NumberFormat |
DEFAULT_NUMBER_FORMAT |
protected double |
maxObs
The largest observation recorded.
|
protected double |
minObs
The smallest observation recorded.
|
protected java.lang.String |
name
The name of the property that this SampleStatistic will collect
statistics on.
|
protected java.text.NumberFormat |
numberFormat
The DecimalFormat used for Strings.
|
EOL
Constructor and Description |
---|
AbstractSimpleStats()
Creates a new instance with the default name "%unnamed%"
|
AbstractSimpleStats(java.lang.String name)
Creates a new instance with the given name.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Clone this instance
|
int |
getCount()
Gets the number of observations so far.
|
java.lang.String |
getDataLine()
Returns the data line consisting of the count, min, max, mean, variance,
and standard deviation.
|
double |
getMaxObs()
Gets the maximum observed value so far.
|
double |
getMinObs()
Gets the minimum observed value so far.
|
java.lang.String |
getName() |
void |
newObservation(boolean newObs)
Add a new Observation of type
boolean . |
void |
newObservation(java.lang.Boolean newObs)
Add a new Observation of type
Boolean . |
void |
newObservation(double newObs)
Add new observation and update counters (primitive).
|
void |
newObservation(java.lang.Number newObs)
Add new observation and update counters - normally will just call
newObservation(newObs.doubleValue()).
|
void |
propertyChange(java.beans.PropertyChangeEvent e)
If the PropertyChangeEvent contains the property this SampleStatistic is
associated with, record the value as a new observation.
|
void |
reset()
Should reset/initialize all relevant counters.
|
void |
setName(java.lang.String name) |
void |
setNumberFormat(java.text.NumberFormat numberFormat)
Sets the NumberFormat
|
void |
setSamplingType(SamplingType type)
Sets the sampling type to either TALLY or TIME_VARYING.
|
java.lang.String |
toString()
Return a String containing the Name, SamplingType, and the DataLine for
this SampleStatistic.
|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getMean, getSamplingType, getStandardDeviation, getVariance
protected static final java.lang.String DEFAULT_NAME
public static final java.text.NumberFormat DEFAULT_NUMBER_FORMAT
protected int count
protected double minObs
protected double maxObs
protected java.lang.String name
protected java.text.NumberFormat numberFormat
public AbstractSimpleStats()
public AbstractSimpleStats(java.lang.String name)
name
- given namepublic double getMaxObs()
SampleStatistics
getMaxObs
in interface SampleStatistics
public double getMinObs()
SampleStatistics
getMinObs
in interface SampleStatistics
public int getCount()
SampleStatistics
getCount
in interface SampleStatistics
public void reset()
SampleStatistics
reset
in interface SampleStatistics
public void newObservation(double newObs)
SampleStatistics
newObservation
in interface SampleStatistics
newObs
- The new (primitive) observationpublic void newObservation(java.lang.Number newObs)
newObservation
in interface SampleStatistics
newObs
- The new (Number) observationpublic void propertyChange(java.beans.PropertyChangeEvent e)
If the name of the property is "reset" and the value of the property is the name of the property that this SampleStatistic is associated with, then reset this SampleStatistic.
propertyChange
in interface java.beans.PropertyChangeListener
e
- Given PropertyChangeEventpublic void setSamplingType(SamplingType type)
SampleStatistics
setSamplingType
in interface SampleStatistics
type
- The SamplingType (TALLY or TIME_VARYING).public void setNumberFormat(java.text.NumberFormat numberFormat)
SampleStatistics
setNumberFormat
in interface SampleStatistics
numberFormat
- the new DecimalFormat instancepublic void newObservation(java.lang.Boolean newObs)
SampleStatistics
Boolean
. It is expected that
"true" corresponds to '1' and "false" to 0.newObservation
in interface SampleStatistics
newObs
- the Boolean observationpublic void newObservation(boolean newObs)
boolean
. It is expected that
"true" corresponds to '1' and "false" to 0.newObservation
in interface SampleStatistics
newObs
- the boolean observationpublic java.lang.String getName()
getName
in interface Named
getName
in interface SampleStatistics
public void setName(java.lang.String name)
setName
in interface Named
setName
in interface SampleStatistics
name
- The new name of the Object.public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
getDataLine()
public java.lang.String getDataLine()