Class OnChangeRTIndicator
java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractIncrementalRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractDecorableIncrementalRTIndicator
com.wualabs.qtsurfer.engine.indicators.helpers.OnChangeRTIndicator
- All Implemented Interfaces:
ClockAware, Resettable, RTIndicator
- Direct Known Subclasses:
WindowTimeRTIndicator
Incremental indicator that fires change notifications to registered listeners
whenever its value changes. Its
StateStore is pluggable — see
setStateStoreSupplier(Supplier) — and is only materialized when a listener is actually there to
receive it. Events can be disabled via setEnableEvents(boolean).-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidResolves this indicator's state store: the externally supplied one ifsetStateStoreSupplier(Supplier)was called, otherwise a private in-memory store created on demand.protected booleanbooleanprotected doublenextValue(double prevValue, double newValue) Fires change notifications (if events are enabled) before delegating to the parent's nextValue computation.protected voidnotifyOnChange(double prevValue, double newValue) Broadcasts the value change to all registered listeners, resolving the state store exactly once per event and handing it to each listener directly, so a listener body is its logic — no factory unwrapping.protected voidnotifyOnChange(@NonNull StateStore store, double prevValue, double newValue) Broadcasts with a store the caller already resolved, so an event that had to write state itself does not resolve twice.voidvoidsetEnableEvents(boolean enableEvents) voidsetStateStoreSupplier(@NonNull Supplier<StateStore> stateStoreSupplier) Routes this indicator's state at an externally owned store, typically the one shared by every indicator of an instrument.protected com.google.common.base.MoreObjects.ToStringHelpertoString(com.google.common.base.MoreObjects.ToStringHelper ts) Methods inherited from class AbstractDecorableIncrementalRTIndicator
getIndicator, reset, setClockSupplier, updateMethods inherited from class AbstractIncrementalRTIndicator
getLastUpdateValue, getPeriodCycles, getPeriods, getPrevValue, initValue, isPeriodic, isReady, prevNextValue, setPeriods, tickValueMethods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, withDisplayHint, withMeta
-
Constructor Details
-
OnChangeRTIndicator
public OnChangeRTIndicator() -
OnChangeRTIndicator
-
-
Method Details
-
setEnableEvents
public void setEnableEvents(boolean enableEvents) -
isEnableEvents
public boolean isEnableEvents() -
addOnChangeListener
-
removeOnChangeListener
-
clearOnChangeListeners
public void clearOnChangeListeners() -
hasListeners
protected boolean hasListeners()- Returns:
- whether any listener is registered — the gate that decides if a store is needed at all
-
setStateStoreSupplier
Routes this indicator's state at an externally owned store, typically the one shared by every indicator of an instrument. The supplier is consulted lazily, on the events that actually write , so wiring an indicator up costs nothing until it has something to persist — which matters once the store behind it is a persistent backend rather than a map.- Parameters:
stateStoreSupplier- supplies the store to use instead of this indicator's own
-
getStateStore
Resolves this indicator's state store: the externally supplied one ifsetStateStoreSupplier(Supplier)was called, otherwise a private in-memory store created on demand. Single accessor on purpose — listeners and callers must never see different stores.- Returns:
- the state store this indicator writes through (never null)
-
nextValue
protected double nextValue(double prevValue, double newValue) Fires change notifications (if events are enabled) before delegating to the parent's nextValue computation. Subclasses like WindowTimeRTIndicator override event enablement to control notification timing.- Overrides:
nextValuein classAbstractDecorableIncrementalRTIndicator- Parameters:
prevValue- the previous indicator value (or last update value, depending on override)newValue- the new input value- Returns:
- the computed indicator value
-
notifyOnChange
protected void notifyOnChange(double prevValue, double newValue) Broadcasts the value change to all registered listeners, resolving the state store exactly once per event and handing it to each listener directly, so a listener body is its logic — no factory unwrapping. With no listeners registered nothing is resolved: the store stays uncreated .- Parameters:
prevValue- the previous indicator valuenewValue- the new indicator value
-
notifyOnChange
protected void notifyOnChange(@NonNull @NonNull StateStore store, double prevValue, double newValue) Broadcasts with a store the caller already resolved, so an event that had to write state itself does not resolve twice.- Parameters:
store- the store to hand to every listenerprevValue- the previous indicator valuenewValue- the new indicator value
-
toString
protected com.google.common.base.MoreObjects.ToStringHelper toString(com.google.common.base.MoreObjects.ToStringHelper ts) - Overrides:
toStringin classAbstractRTIndicator
-