Class MonitoredValue<T>

java.lang.Object
com.amalgamasimulation.engine.MonitoredValue<T>
Type Parameters:
T - the type of elements associated with thresholds

public class MonitoredValue<T> extends Object
Class representing a value that changes at the specified rate as the simulation time goes and fires notifications when the value hits the specified thresholds.

The rates at which the monitored value increases or decreases can be changed by calling setRate(double) method. Current value can be instantly changed by calling setCurrentValue(double, boolean) method.

Thresholds can be added by calling addThreshold(double, Object) method.

Author:
Vitaliy Chernenko
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of the monitored value.
    MonitoredValue(Engine engine, BiConsumer<Double,List<T>> thresholdActionHandler)
    Creates a new instance of the monitored value.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAction(BiConsumer<Double,List<T>> thresholdActionHandler)
    Adds the specified handler of threshold hit action.
    void
    addThreshold(double threshold, T value)
    Adds a threshold that must be monitored and the value associated with this threshold.
    double
    Returns the rate at which this monitored value is currently changing.
    double
    Returns the current value of this monitored value.
    void
    setCurrentValue(double newValue)
    Instantly changes this monitored value to the specified new value.
    void
    setCurrentValue(double newValue, boolean checkThresholds)
    Instantly changes this monitored value to the specified new value.
    void
    setRate(double newRate)
    Sets the new rate at which this monitored value will be changing.

    Methods inherited from class java.lang.Object

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

    • MonitoredValue

      public MonitoredValue(Engine engine)
      Creates a new instance of the monitored value.
      Parameters:
      engine - instance of Engine used to simulate dynamics of this monitored value
    • MonitoredValue

      public MonitoredValue(Engine engine, BiConsumer<Double,List<T>> thresholdActionHandler)
      Creates a new instance of the monitored value.
      Parameters:
      engine - instance of Engine used to simulate dynamics of this monitored value
      thresholdActionHandler - handler called when any threshold gets hit by this monitored value
  • Method Details

    • addAction

      public void addAction(BiConsumer<Double,List<T>> thresholdActionHandler)
      Adds the specified handler of threshold hit action.
      Parameters:
      thresholdActionHandler - handler called when any threshold gets hit by this monitored value
    • addThreshold

      public void addThreshold(double threshold, T value)
      Adds a threshold that must be monitored and the value associated with this threshold.
      Parameters:
      threshold - threshold that must be monitored
      value - value associated with the specified threshold
    • getCurrentRate

      public double getCurrentRate()
      Returns the rate at which this monitored value is currently changing.
      Returns:
      rate at which this monitored value is currently changing
    • setRate

      public void setRate(double newRate)
      Sets the new rate at which this monitored value will be changing. Can cause threshold hit events to be fired if current value is equal to some threshold.
      Parameters:
      newRate - new rate
    • getCurrentValue

      public double getCurrentValue()
      Returns the current value of this monitored value.
      Returns:
      the current value
    • setCurrentValue

      public void setCurrentValue(double newValue, boolean checkThresholds)
      Instantly changes this monitored value to the specified new value.
      Parameters:
      newValue - specified new value
      checkThresholds - if true, then the thresholds will be checked and events fired if the newValue is equals to one of the thresholds
    • setCurrentValue

      public void setCurrentValue(double newValue)
      Instantly changes this monitored value to the specified new value. Does not check the thresholds and thus never fires any threshold events.
      Parameters:
      newValue - specified new value