com.isti.util
Class Averager

java.lang.Object
  extended bycom.isti.util.Averager

public class Averager
extends java.lang.Object

Class Averager implements a "windowed" average, where the average of the last 'n' values entered is calculated.


Constructor Summary
Averager(int windowSize)
          Creates a "windowed" averaging object.
 
Method Summary
 void clear()
          Clears the averaging "window" back to its initial state.
 long enter(long val)
          Enters the new value into the averaging "window".
 long getAverage()
          Returns the current average of values in the "window".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Averager

public Averager(int windowSize)
Creates a "windowed" averaging object.

Parameters:
windowSize - the number of values to track and use when computing the average. If the value is not greater than zero then a runtime exception is thrown.
Method Detail

clear

public void clear()
Clears the averaging "window" back to its initial state. All values are set to zero.


enter

public long enter(long val)
Enters the new value into the averaging "window".

Parameters:
val - the value to be entered.
Returns:
The new calculated average.

getAverage

public long getAverage()
Returns the current average of values in the "window".

Returns:
the current average of values in the "window".