Class WindowAccumulator

java.lang.Object
com.amalgamasimulation.utils.windowaccumulator.WindowAccumulator
All Implemented Interfaces:
IWindowAccumulator

public class WindowAccumulator extends Object implements IWindowAccumulator
A class implementing a window accumulator for a sliding window of a fixed size. It accumulates values added within a certain time window and allows querying of statistical properties like sum, average, maximum, and minimum for the values within this window.
Author:
Alexey Kirillov
  • Constructor Summary

    Constructors
    Constructor
    Description
    WindowAccumulator(double timeWindowSize)
    Standard constructor for the sliding window accumulator.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(double time, double value)
    Adds a new statistical element to the accumulator.
    void
    Clears all the data from the accumulator.
    void
    compress(double time)
    Removes all outdated values relative to the specified time from the accumulator, effectively compressing the stored data to fit within the current time window.
    double
    get()
    Returns the sum of all values currently stored in the accumulator.
    double
    get(double time)
    Returns the sum of elements in the accumulator whose time of addition does not exceed the specified time.
    double
    Returns the average value of all elements currently stored in the accumulator.
    double
    getAvg(double time)
    Returns the average value among all elements in the accumulator whose time of addition does not exceed the specified time.
    double
    getMax(double time)
    Returns the maximum value among all elements in the accumulator whose time of addition does not exceed the specified time.
    double
    getMin(double time)
    Returns the minimum value among all elements in the accumulator whose time of addition does not exceed the specified time.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WindowAccumulator

      public WindowAccumulator(double timeWindowSize)
      Standard constructor for the sliding window accumulator.
      Parameters:
      timeWindowSize - The duration (length) of the time window.
  • Method Details

    • add

      public void add(double time, double value)
      Description copied from interface: IWindowAccumulator
      Adds a new statistical element to the accumulator.
      Specified by:
      add in interface IWindowAccumulator
      Parameters:
      time - The time associated with the statistical element.
      value - The value of the statistical element.
    • get

      public double get(double time)
      Description copied from interface: IWindowAccumulator
      Returns the sum of elements in the accumulator whose time of addition does not exceed the specified time.
      Specified by:
      get in interface IWindowAccumulator
      Parameters:
      time - The maximum time up to which values are accumulated.
      Returns:
      The sum of elements added to the accumulator up to the specified time.
    • get

      public double get()
      Returns the sum of all values currently stored in the accumulator.
      Returns:
      The total sum of all values in the accumulator.
    • getAvg

      public double getAvg(double time)
      Description copied from interface: IWindowAccumulator
      Returns the average value among all elements in the accumulator whose time of addition does not exceed the specified time.
      Specified by:
      getAvg in interface IWindowAccumulator
      Parameters:
      time - The maximum time up to which values are considered for averaging.
      Returns:
      The average value of elements up to the specified time.
    • getAvg

      public double getAvg()
      Returns the average value of all elements currently stored in the accumulator.
      Returns:
      The average of all values in the accumulator.
    • getMax

      public double getMax(double time)
      Description copied from interface: IWindowAccumulator
      Returns the maximum value among all elements in the accumulator whose time of addition does not exceed the specified time.
      Specified by:
      getMax in interface IWindowAccumulator
      Parameters:
      time - The maximum time up to which values are considered for finding the maximum.
      Returns:
      The maximum value of elements up to the specified time.
    • getMin

      public double getMin(double time)
      Description copied from interface: IWindowAccumulator
      Returns the minimum value among all elements in the accumulator whose time of addition does not exceed the specified time.
      Specified by:
      getMin in interface IWindowAccumulator
      Parameters:
      time - The maximum time up to which values are considered for finding the minimum.
      Returns:
      The minimum value of elements up to the specified time.
    • compress

      public void compress(double time)
      Removes all outdated values relative to the specified time from the accumulator, effectively compressing the stored data to fit within the current time window.
      Parameters:
      time - The reference time for the compression operation.
    • clear

      public void clear()
      Description copied from interface: IWindowAccumulator
      Clears all the data from the accumulator.
      Specified by:
      clear in interface IWindowAccumulator