25package umontreal.ssj.stat;
28import java.util.ArrayList;
29import umontreal.ssj.util.PrintfFormat;
62 private List<ObservationListener> listeners =
new ArrayList<ObservationListener>();
63 protected String name;
64 protected double maxValue;
65 protected double minValue;
66 protected double sumValue;
67 protected boolean collect =
true;
68 protected boolean broadcast =
false;
69 protected boolean showNobs =
true;
74 abstract public void init();
195 if (firstProbe ==
null)
198 if (s !=
null && s.length() > maxn)
201 if (firstProbe ==
null)
203 StringBuffer sb =
new StringBuffer(
"Report for ");
205 for (
int i = 0; i < maxn; i++)
214 return sb.toString();
227 public static String
report(String globalName, Iterable<? extends StatProbe> probes) {
231 if (firstProbe ==
null)
234 int sl = s ==
null ? 4 : s.length();
238 if (firstProbe ==
null)
240 StringBuffer sb =
new StringBuffer(
"Report for ");
242 for (
int i = 0; i < maxn; i++)
251 return sb.toString();
307 throw new NullPointerException();
308 if (!listeners.contains(l))
338 final int nl = listeners.size();
339 for (
int i = 0; i < nl; i++)
340 listeners.get(i).newObservation(
this, x);
343 public StatProbe clone() throws CloneNotSupportedException {
345 s.listeners =
new ArrayList<ObservationListener>(listeners);
The objects of this class are statistical probes or collectors, which are elementary devices for coll...
void notifyListeners(double x)
Notifies the observation x to all registered observers if broadcasting is ON.
abstract String shortReportHeader()
Returns a string containing the name of the values returned in the report strings.
abstract String shortReport()
Formats and returns a short, one-line report about this statistical probe.
boolean isCollecting()
Determines if this statistical probe is collecting values.
void removeObservationListener(ObservationListener l)
Removes the observation listener l from the list of observers of this statistical probe.
void addObservationListener(ObservationListener l)
Adds the observation listener l to the list of observers of this statistical probe.
abstract double average()
Returns the average for this collector.
abstract void init()
Initializes the statistical collector.
String getName()
Returns the name associated with this probe, or null if no name was specified upon construction.
boolean isBroadcasting()
Determines if this statistical probe is broadcasting observations to registered observers.
void setBroadcasting(boolean b)
Instructs the probe to turn its broadcasting ON or OFF.
double min()
Returns the smallest value taken by the variable since the last initialization of this probe.
static String report(String globalName, Iterable<? extends StatProbe > probes)
Equivalent to report(String,StatProbe[]), except that probes is an Iterable object instead of an arra...
void setName(String name)
Sets the name of this statistical collector to name.
void setCollecting(boolean b)
Turns ON or OFF the collection of statistical observations.
abstract String report()
Returns a string containing a report for this statistical collector.
double sum()
Returns the sum cumulated so far for this probe.
double max()
Returns the largest value taken by the variable since the last initialization of this probe.
void clearObservationListeners()
Removes all observation listeners from the list of observers of this statistical probe.
static String report(String globalName, StatProbe[] probes)
Formats short reports for each statistical probe in the array probes while aligning the probes’ names...
Represents an object that can listen to observations broadcast by statistical probes.