org.carrot2.util
Class RollingWindowAverage

java.lang.Object
  extended by org.carrot2.util.RollingWindowAverage

public class RollingWindowAverage
extends Object

Calculates an average of values showing up in a given time window. To keep processing efficient, bucketing is performed.

This class is not thread-safe.


Field Summary
static int MILLIS
          Helpful constant for one millisecond.
static int MINUTE
          Helpful constant for one minute.
static int SECOND
          Helpful constant for one second.
 
Constructor Summary
RollingWindowAverage(long windowSizeMillis, long bucketSizeMillis)
           
 
Method Summary
 void add(long timestamp, long value)
          Adds a new entry.
 double getCurrentAverage()
           
 long getUpdatesInWindow()
          Returns the number of updates kept in the rolling window's scope.
 long getWindowSizeMillis()
          Returns the size of the rolling window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MILLIS

public static final int MILLIS
Helpful constant for one millisecond.

See Also:
Constant Field Values

SECOND

public static final int SECOND
Helpful constant for one second.

See Also:
Constant Field Values

MINUTE

public static final int MINUTE
Helpful constant for one minute.

See Also:
Constant Field Values
Constructor Detail

RollingWindowAverage

public RollingWindowAverage(long windowSizeMillis,
                            long bucketSizeMillis)
Method Detail

add

public final void add(long timestamp,
                      long value)
Adds a new entry.


getCurrentAverage

public final double getCurrentAverage()

getUpdatesInWindow

public final long getUpdatesInWindow()
Returns the number of updates kept in the rolling window's scope.


getWindowSizeMillis

public final long getWindowSizeMillis()
Returns the size of the rolling window.



Copyright (c) Dawid Weiss, Stanislaw Osinski