public synchronized void update(double sample){
  long now=System.currentTimeMillis();
  if (lastMillis == 0) {
    average=sample;
    lastMillis=now;
    return;
  }
  long deltaTime=now - lastMillis;
  double coeff=Math.exp(-1.0 * ((double)deltaTime / windowMillis));
  average=(1.0 - coeff) * sample + coeff * average;
  lastMillis=now;
}

public synchronized void update ( double sample ) { long now = System . currentTimeMillis ( ) ; if ( lastMillis == 0 ) { average = sample ; lastMillis = now ; return ; } long deltaTime = now - lastMillis ; double coeff = Math . exp ( - 1.0 * ( ( double ) deltaTime / windowMillis ) ) ; average = ( 1.0 - coeff ) * sample + coeff * average ; lastMillis = now ; }
updates the average with the latest measurement .
