Package com.amalgamasimulation.engine
Class MonitoredValue<T>
java.lang.Object
com.amalgamasimulation.engine.MonitoredValue<T>
- Type Parameters:
T
- the type of elements associated with thresholds
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
ConstructorsConstructorDescriptionMonitoredValue
(Engine engine) 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 TypeMethodDescriptionvoid
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.
-
Constructor Details
-
MonitoredValue
Creates a new instance of the monitored value.- Parameters:
engine
- instance ofEngine
used to simulate dynamics of this monitored value
-
MonitoredValue
Creates a new instance of the monitored value.- Parameters:
engine
- instance ofEngine
used to simulate dynamics of this monitored valuethresholdActionHandler
- handler called when any threshold gets hit by this monitored value
-
-
Method Details
-
addAction
Adds the specified handler of threshold hit action.- Parameters:
thresholdActionHandler
- handler called when any threshold gets hit by this monitored value
-
addThreshold
Adds a threshold that must be monitored and the value associated with this threshold.- Parameters:
threshold
- threshold that must be monitoredvalue
- 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 valuecheckThresholds
- iftrue
, 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
-