Class VariableListenerSupport<Solution_>
java.lang.Object
ai.timefold.solver.core.impl.domain.variable.listener.support.VariableListenerSupport<Solution_>
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation
- All Implemented Interfaces:
SupplyManager
@NullMarked
public final class VariableListenerSupport<Solution_>
extends Object
implements SupplyManager
This class is not thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionvoidafterElementUnassigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element) voidafterListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex) voidafterVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity) voidvoidbeforeEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity) voidbeforeEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity) voidbeforeListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex) voidbeforeVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity) <Supply_ extends Supply>
booleanCancel an activeSupplyManager.demand(Demand).voidClear all variable listeners without triggering any logic.voidclose()static <Solution_>
VariableListenerSupport<Solution_>create(InnerScoreDirector<Solution_, ?> scoreDirector) @Nullable String<Supply_ extends Supply>
Supply_voidforceTriggerAllVariableListeners(Solution_ workingSolution) Triggers all variable listeners even though the notification queue is empty.<Supply_ extends Supply>
longgetActiveCount(Demand<Supply_> demand) voidvoidvoid
-
Method Details
-
create
public static <Solution_> VariableListenerSupport<Solution_> create(InnerScoreDirector<Solution_, ?> scoreDirector) -
getSupportedShadowVariableTypes
-
linkVariableListeners
public void linkVariableListeners() -
demand
Description copied from interface:SupplyManagerReturns theSupplyfor aDemand, preferably an existing one. If theSupplydoesn't exist yet (as part of the domain model or externalized), it creates and attaches it. If twoDemandinstancesare equal, they will result in the sameSupplyinstance. Each supply instance keeps a counter of how many times it was requested, which can be decremented bySupplyManager.cancel(Demand).- Specified by:
demandin interfaceSupplyManager- Type Parameters:
Supply_- Subclass ofSupply- Parameters:
demand- never null- Returns:
- never null
-
cancel
Description copied from interface:SupplyManagerCancel an activeSupplyManager.demand(Demand). Once the number of active demands reaches zero, theSupplyin question is removed.This operation is optional. Supplies with active demands will live for as long as the
SupplyManagerlives, and get garbage-collected together with it.- Specified by:
cancelin interfaceSupplyManager- Parameters:
demand- never null- Returns:
- true if the counter was decremented, false if there is no such supply
-
getActiveCount
- Specified by:
getActiveCountin interfaceSupplyManager- Returns:
- 0 when there is no active
Supplyfor the givenDemand, more when there is one.
-
resetWorkingSolution
public void resetWorkingSolution() -
close
public void close() -
beforeEntityAdded
-
beforeEntityRemoved
-
beforeVariableChanged
-
afterVariableChanged
-
afterElementUnassigned
public void afterElementUnassigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element) -
beforeListVariableChanged
public void beforeListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex) -
afterListVariableChanged
public void afterListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex) -
getScoreDirector
-
triggerVariableListenersInNotificationQueues
public void triggerVariableListenersInNotificationQueues() -
createShadowVariablesViolationMessage
- Returns:
- null if there are no violations
-
forceTriggerAllVariableListeners
Triggers all variable listeners even though the notification queue is empty.To ensure each listener is triggered, an artificial notification is created for each genuine variable without doing any change on the working solution. If everything works correctly, triggering listeners at this point must not change any shadow variables either.
- Parameters:
workingSolution- working solution
-
clearAllVariableListenerEvents
public void clearAllVariableListenerEvents()Clear all variable listeners without triggering any logic. The goal is to clear all queues and avoid executing custom listener logic. -
assertNotificationQueuesAreEmpty
public void assertNotificationQueuesAreEmpty()
-