From 2c382d437966c6384dd9c129d87f2e72cd1ab7a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Petrovick=C3=BD?= Date: Wed, 27 Nov 2024 07:27:12 +0100 Subject: [PATCH] One more --- ...ternalizedNextPrevElementVariableProcessor.java | 2 +- .../ExternalizedIndexVariableProcessor.java | 14 +++++--------- .../ExternalizedListInverseVariableProcessor.java | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/AbstractExternalizedNextPrevElementVariableProcessor.java b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/AbstractExternalizedNextPrevElementVariableProcessor.java index 199dd9fdfc..304fa1fc93 100644 --- a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/AbstractExternalizedNextPrevElementVariableProcessor.java +++ b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/AbstractExternalizedNextPrevElementVariableProcessor.java @@ -26,7 +26,7 @@ public void unsetElement(InnerScoreDirector scoreDirector, Object } protected void setValue(InnerScoreDirector scoreDirector, Object element, Object value) { - if (shadowVariableDescriptor.getValue(element) != value) { + if (getElement(element) != value) { scoreDirector.beforeVariableChanged(shadowVariableDescriptor, element); shadowVariableDescriptor.setValue(element, value); scoreDirector.afterVariableChanged(shadowVariableDescriptor, element); diff --git a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/ExternalizedIndexVariableProcessor.java b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/ExternalizedIndexVariableProcessor.java index aa490c2a88..f3ece2ef83 100644 --- a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/ExternalizedIndexVariableProcessor.java +++ b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/ExternalizedIndexVariableProcessor.java @@ -18,13 +18,7 @@ public void addElement(InnerScoreDirector scoreDirector, Object el } public void removeElement(InnerScoreDirector scoreDirector, Object element) { - setIndex(scoreDirector, element, null); - } - - private void setIndex(InnerScoreDirector scoreDirector, Object element, Object value) { - scoreDirector.beforeVariableChanged(shadowVariableDescriptor, element); - shadowVariableDescriptor.setValue(element, value); - scoreDirector.afterVariableChanged(shadowVariableDescriptor, element); + updateIndex(scoreDirector, element, null); } public void unassignElement(InnerScoreDirector scoreDirector, Object element) { @@ -36,9 +30,11 @@ public void changeElement(InnerScoreDirector scoreDirector, Object } private void updateIndex(InnerScoreDirector scoreDirector, Object element, Integer index) { - var oldIndex = shadowVariableDescriptor.getValue(element); + var oldIndex = getIndex(element); if (!Objects.equals(oldIndex, index)) { - setIndex(scoreDirector, element, index); + scoreDirector.beforeVariableChanged(shadowVariableDescriptor, element); + shadowVariableDescriptor.setValue(element, index); + scoreDirector.afterVariableChanged(shadowVariableDescriptor, element); } } diff --git a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/ExternalizedListInverseVariableProcessor.java b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/ExternalizedListInverseVariableProcessor.java index 8632476fbc..889e587d2a 100644 --- a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/ExternalizedListInverseVariableProcessor.java +++ b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/ExternalizedListInverseVariableProcessor.java @@ -48,7 +48,7 @@ public void removeElement(InnerScoreDirector scoreDirector, Object } public void unassignElement(InnerScoreDirector scoreDirector, Object element) { - setInverse(scoreDirector, null, element); + changeElement(scoreDirector, null, element); } public void changeElement(InnerScoreDirector scoreDirector, Object entity, Object element) {