Class VariableListenerSupport<Solution_>
java.lang.Object
org.optaplanner.core.impl.domain.variable.listener.support.VariableListenerSupport<Solution_>
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation
- All Implemented Interfaces:
SupplyManager
This class is not thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterElementUnassigned
(ListVariableDescriptor<Solution_> variableDescriptor, Object element) void
afterListVariableChanged
(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex) void
void
beforeEntityAdded
(EntityDescriptor<Solution_> entityDescriptor, Object entity) void
beforeEntityRemoved
(EntityDescriptor<Solution_> entityDescriptor, Object entity) void
beforeListVariableChanged
(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex) void
beforeVariableChanged
(VariableDescriptor<Solution_> variableDescriptor, Object entity) <Supply_ extends Supply>
booleanCancel an activeSupplyManager.demand(Demand)
.void
close()
static <Solution_>
VariableListenerSupport<Solution_>create
(InnerScoreDirector<Solution_, ?> scoreDirector) <Supply_ extends Supply>
Supply_void
forceTriggerAllVariableListeners
(Solution_ workingSolution) Triggers all variable listeners even though the notification queue is empty.<Supply_ extends Supply>
longgetActiveCount
(Demand<Supply_> demand) void
void
void
-
Method Details
-
create
public static <Solution_> VariableListenerSupport<Solution_> create(InnerScoreDirector<Solution_, ?> scoreDirector) -
linkVariableListeners
public void linkVariableListeners() -
demand
Description copied from interface:SupplyManager
Returns theSupply
for aDemand
, preferably an existing one. If theSupply
doesn't exist yet (as part of the domain model or externalized), it creates and attaches it. If twoDemand
instancesare equal
, they will result in the sameSupply
instance. Each supply instance keeps a counter of how many times it was requested, which can be decremented bySupplyManager.cancel(Demand)
.- Specified by:
demand
in interfaceSupplyManager
- Type Parameters:
Supply_
- Subclass ofSupply
- Parameters:
demand
- never null- Returns:
- never null
-
cancel
Description copied from interface:SupplyManager
Cancel an activeSupplyManager.demand(Demand)
. Once the number of active demands reaches zero, theSupply
in question is removed.This operation is optional. Supplies with active demands will live for as long as the
SupplyManager
lives, and get garbage-collected together with it.- Specified by:
cancel
in interfaceSupplyManager
- Parameters:
demand
- never null- Returns:
- true if the counter was decremented, false if there is no such supply
-
getActiveCount
- Specified by:
getActiveCount
in interfaceSupplyManager
- Returns:
- 0 when there is no active
Supply
for the givenDemand
, more when there is one.
-
resetWorkingSolution
public void resetWorkingSolution() -
close
public void close() -
beforeEntityAdded
-
beforeEntityRemoved
-
beforeVariableChanged
-
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) -
triggerVariableListenersInNotificationQueues
public void triggerVariableListenersInNotificationQueues() -
createShadowVariablesViolationMessage
- Returns:
- null if there are no violations
-
forceTriggerAllVariableListeners
Triggers all variable listeners even though the notification queue is empty.- Parameters:
workingSolution
- working solution
-
assertNotificationQueuesAreEmpty
public void assertNotificationQueuesAreEmpty()
-