All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.l4.vibe.probes.AveragingProbe Maven / Gradle / Ivy

There is a newer version: 0.4.0
Show newest version
package se.l4.vibe.probes;

/**
 * Probe similar to {@link CountingProbe} that averages its inputs.
 * 
 * @author Andreas Holstenson
 *
 */
public class AveragingProbe
	extends AbstractSampledProbe
{
	private double value;
	private int samples;
	
	public AveragingProbe()
	{
	}
	
	/**
	 * Add a value to this probe.
	 * 
	 * @param value
	 */
	public void add(double value)
	{
		value += value;
		samples++;
	}

	@Override
	public Double peek()
	{
		return value / samples;
	}

	@Override
	protected Double sample0()
	{
		double v = value / samples;
		value = 0;
		samples = 0;
		return v;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy