Skip to content

Commit f2f2ddd

Browse files
committed
refactor: remove all leftover deprecations
1 parent 15e593f commit f2f2ddd

124 files changed

Lines changed: 1085 additions & 1118 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ai.timefold.solver.core.api.domain.common;
2+
3+
import ai.timefold.solver.core.api.solver.change.ProblemChange;
4+
import ai.timefold.solver.core.preview.api.move.Move;
5+
6+
import org.jspecify.annotations.Nullable;
7+
8+
/**
9+
* Allows to transfer an entity or fact instance (often from another {@link Thread})
10+
* to another working solution.
11+
*/
12+
public interface Lookup {
13+
14+
/**
15+
* Translates an entity or fact instance (often from another {@link Thread})
16+
* to another working solution.
17+
* Useful for {@link Move#rebase(Lookup) move rebasing}
18+
* and in a {@link ProblemChange} and for multi-threaded solving.
19+
* <p>
20+
* Matching uses {@link PlanningId}.
21+
*
22+
* @param problemFactOrPlanningEntity The fact or entity to rebase.
23+
* @return null if problemFactOrPlanningEntity is null
24+
* @throws IllegalArgumentException if there is no working object for the fact or entity,
25+
* if it cannot be looked up,
26+
* or if its class is not supported.
27+
* @throws IllegalStateException if it cannot be looked up
28+
* @param <T> the object type
29+
*/
30+
<T> @Nullable T lookUpWorkingObject(@Nullable T problemFactOrPlanningEntity);
31+
32+
}

core/src/main/java/ai/timefold/solver/core/api/domain/common/PlanningId.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
import ai.timefold.solver.core.api.domain.valuerange.ValueRangeProvider;
1313
import ai.timefold.solver.core.api.solver.change.ProblemChange;
1414
import ai.timefold.solver.core.preview.api.move.Move;
15-
import ai.timefold.solver.core.preview.api.move.Rebaser;
1615

1716
/**
1817
* Specifies that a bean property (or a field) is the id to match
19-
* when {@link Rebaser#rebase(Object) locating}
18+
* when {@link Lookup#lookUpWorkingObject(Object) looking up}
2019
* an externalObject (often from another {@link Thread} or JVM).
2120
* Used during {@link Move} rebasing and in a {@link ProblemChange}.
2221
* <p>

core/src/main/java/ai/timefold/solver/core/api/domain/solution/PlanningEntityProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Specifies that a property (or a field) on a {@link PlanningSolution} class is a planning entity.
1414
* <p>
1515
* The planning entity should have the {@link PlanningEntity} annotation.
16-
* The planning entity will be added registered with the solver.
16+
* The planning entity will be registered with the solver.
1717
*/
1818
@Target({ METHOD, FIELD })
1919
@Retention(RUNTIME)

core/src/main/java/ai/timefold/solver/core/api/solver/change/ProblemChangeDirector.java

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package ai.timefold.solver.core.api.solver.change;
22

3-
import java.util.Optional;
43
import java.util.function.Consumer;
54

6-
import ai.timefold.solver.core.api.domain.common.PlanningId;
5+
import ai.timefold.solver.core.api.domain.common.Lookup;
76
import ai.timefold.solver.core.api.domain.entity.PlanningEntity;
87
import ai.timefold.solver.core.api.domain.solution.PlanningSolution;
98
import ai.timefold.solver.core.api.domain.variable.PlanningVariable;
109
import ai.timefold.solver.core.api.domain.variable.ShadowVariable;
1110

1211
import org.jspecify.annotations.NullMarked;
13-
import org.jspecify.annotations.Nullable;
1412

1513
/**
1614
* Allows external changes to the {@link PlanningSolution working solution}. If the changes are not applied through
@@ -19,9 +17,12 @@
1917
* never notified about them, resulting to inconsistencies in the {@link PlanningSolution working solution}.
2018
* Should be used only from a {@link ProblemChange} implementation.
2119
* To see an example implementation, please refer to the {@link ProblemChange} Javadoc.
20+
*
21+
* @see Lookup You may need to perform lookups of working objects from external objects.
2222
*/
2323
@NullMarked
24-
public interface ProblemChangeDirector {
24+
public interface ProblemChangeDirector
25+
extends Lookup {
2526

2627
/**
2728
* Add a new {@link PlanningEntity} instance into the {@link PlanningSolution working solution}.
@@ -35,7 +36,7 @@ public interface ProblemChangeDirector {
3536
/**
3637
* Remove an existing {@link PlanningEntity} instance from the {@link PlanningSolution working solution}.
3738
* Translates the entity to a working planning entity by performing a lookup as defined by
38-
* {@link #lookUpWorkingObjectOrFail(Object)}.
39+
* {@link #lookUpWorkingObject(Object)}.
3940
*
4041
* @param entity the {@link PlanningEntity} instance
4142
* @param entityConsumer removes the working entity from the {@link PlanningSolution working solution}
@@ -45,7 +46,7 @@ public interface ProblemChangeDirector {
4546

4647
/**
4748
* Change a {@link PlanningVariable} value of a {@link PlanningEntity}. Translates the entity to a working
48-
* planning entity by performing a lookup as defined by {@link #lookUpWorkingObjectOrFail(Object)}.
49+
* planning entity by performing a lookup as defined by {@link #lookUpWorkingObject(Object)}.
4950
*
5051
* @param entity the {@link PlanningEntity} instance
5152
* @param variableName name of the {@link PlanningVariable}
@@ -66,7 +67,7 @@ public interface ProblemChangeDirector {
6667

6768
/**
6869
* Remove an existing problem fact from the {@link PlanningSolution working solution}. Translates the problem fact
69-
* to a working problem fact by performing a lookup as defined by {@link #lookUpWorkingObjectOrFail(Object)}.
70+
* to a working problem fact by performing a lookup as defined by {@link #lookUpWorkingObject(Object)}.
7071
*
7172
* @param problemFact the problem fact instance
7273
* @param problemFactConsumer removes the working problem fact from the
@@ -78,7 +79,7 @@ public interface ProblemChangeDirector {
7879
/**
7980
* Change a property of either a {@link PlanningEntity} or a problem fact. Translates the entity or the problem fact
8081
* to its {@link PlanningSolution working solution} counterpart by performing a lookup as defined by
81-
* {@link #lookUpWorkingObjectOrFail(Object)}.
82+
* {@link #lookUpWorkingObject(Object)}.
8283
*
8384
* @param problemFactOrEntity the {@link PlanningEntity} or the problem fact instance
8485
* @param problemFactOrEntityConsumer updates the property of the {@link PlanningEntity}
@@ -88,32 +89,6 @@ public interface ProblemChangeDirector {
8889
<EntityOrProblemFact> void changeProblemProperty(EntityOrProblemFact problemFactOrEntity,
8990
Consumer<EntityOrProblemFact> problemFactOrEntityConsumer);
9091

91-
/**
92-
* Translate an entity or fact instance (often from another {@link Thread} or JVM)
93-
* to this {@link ProblemChangeDirector}'s internal working instance.
94-
* <p>
95-
* Matching uses {@link PlanningId}.
96-
*
97-
* @return null if externalObject is null
98-
* @throws IllegalArgumentException if there is no workingObject for externalObject, if it cannot be looked up
99-
* or if the externalObject's class is not supported
100-
* @throws IllegalStateException if it cannot be looked up
101-
* @param <EntityOrProblemFact> the object type
102-
*/
103-
<EntityOrProblemFact> @Nullable EntityOrProblemFact lookUpWorkingObjectOrFail(@Nullable EntityOrProblemFact externalObject);
104-
105-
/**
106-
* As defined by {@link #lookUpWorkingObjectOrFail(Object)},
107-
* but doesn't fail fast if no workingObject was ever added for the externalObject.
108-
* It's recommended to use {@link #lookUpWorkingObjectOrFail(Object)} instead.
109-
*
110-
* @return {@link Optional#empty()} if there is no workingObject for externalObject, or if externalObject is null
111-
* @throws IllegalArgumentException if it cannot be looked up or if the externalObject's class is not supported
112-
* @throws IllegalStateException if it cannot be looked up
113-
* @param <EntityOrProblemFact> the object type
114-
*/
115-
<EntityOrProblemFact> Optional<EntityOrProblemFact> lookUpWorkingObject(@Nullable EntityOrProblemFact externalObject);
116-
11792
/**
11893
* Calls variable listeners on the external changes submitted so far.
11994
*

core/src/main/java/ai/timefold/solver/core/api/solver/phase/PhaseCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public interface PhaseCommand<Solution_> {
2020
/**
2121
* Changes the current {@link PhaseCommandContext#getWorkingSolution() working solution}.
2222
* The solver is notified of the changes through {@link PhaseCommandContext},
23-
* specifically through {@link PhaseCommandContext#execute(Move)}.
23+
* specifically through {@link PhaseCommandContext#executeAndCalculateScore(Move)}.
2424
* Any other modifications to the working solution are strictly forbidden
2525
* and will likely cause the solver to be in an inconsistent state and throw an exception later on.
2626
* <p>

core/src/main/java/ai/timefold/solver/core/api/solver/phase/PhaseCommandContext.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import java.util.function.Function;
44

5+
import ai.timefold.solver.core.api.domain.common.Lookup;
6+
import ai.timefold.solver.core.api.score.Score;
57
import ai.timefold.solver.core.preview.api.domain.metamodel.PlanningSolutionMetaModel;
68
import ai.timefold.solver.core.preview.api.move.Move;
7-
import ai.timefold.solver.core.preview.api.move.Rebaser;
89

910
import org.jspecify.annotations.NullMarked;
1011
import org.jspecify.annotations.Nullable;
@@ -17,7 +18,8 @@
1718
* @see PhaseCommand
1819
*/
1920
@NullMarked
20-
public interface PhaseCommandContext<Solution_> {
21+
public interface PhaseCommandContext<Solution_>
22+
extends Lookup {
2123

2224
/**
2325
* Returns the meta-model of the {@link #getWorkingSolution() working solution}.
@@ -29,7 +31,7 @@ public interface PhaseCommandContext<Solution_> {
2931
/**
3032
* Returns the current working solution.
3133
* It must not be modified directly,
32-
* but only through {@link #execute(Move)} or {@link #executeTemporarily(Move, Function)}.
34+
* but only through {@link #executeAndCalculateScore(Move)} or {@link #executeTemporarily(Move, Function)}.
3335
* Direct modifications will cause the solver to be in an inconsistent state and likely throw an exception later on.
3436
*
3537
* @return the current working solution
@@ -47,23 +49,21 @@ public interface PhaseCommandContext<Solution_> {
4749
boolean isPhaseTerminated();
4850

4951
/**
50-
* As defined by {@link #execute(Move, boolean)},
51-
* but with the guarantee of a fresh score.
52+
* Executes the given move and updates the working solution
53+
* without recalculating the score for performance reasons.
54+
*
55+
* @param move the move to execute
5256
*/
53-
default void execute(Move<Solution_> move) {
54-
execute(move, true);
55-
}
57+
void execute(Move<Solution_> move);
5658

5759
/**
5860
* Executes the given move and updates the working solution,
59-
* optionally without recalculating the score for performance reasons.
61+
* and returns the new score of the working solution.
6062
*
6163
* @param move the move to execute
62-
* @param guaranteeFreshScore if true, the score of {@link #getWorkingSolution()} after this method returns
63-
* is guaranteed to be up-to-date;
64-
* otherwise it may be stale as the solver will skip recalculating it for performance reasons.
64+
* @return the new score of the working solution after executing the move
6565
*/
66-
void execute(Move<Solution_> move, boolean guaranteeFreshScore);
66+
<Score_ extends Score<Score_>> Score_ executeAndCalculateScore(Move<Solution_> move);
6767

6868
/**
6969
* As defined by {@link #executeTemporarily(Move, Function, boolean)},
@@ -90,9 +90,7 @@ default void execute(Move<Solution_> move) {
9090
<Result_> @Nullable Result_ executeTemporarily(Move<Solution_> move,
9191
Function<Solution_, @Nullable Result_> temporarySolutionConsumer, boolean guaranteeFreshScore);
9292

93-
/**
94-
* As defined by {@link Rebaser#rebase(Object)}, but for the working solution of this context.
95-
*/
96-
<T> @Nullable T lookupWorkingObject(@Nullable T original);
93+
@Override
94+
<T> @Nullable T lookUpWorkingObject(@Nullable T problemFactOrPlanningEntity);
9795

9896
}

core/src/main/java/ai/timefold/solver/core/impl/bavet/common/AbstractNodeBuildHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ai.timefold.solver.core.impl.bavet.common;
22

3-
import static ai.timefold.solver.core.impl.bavet.common.ConstraintNodeProfileId.*;
3+
import static ai.timefold.solver.core.impl.bavet.common.ConstraintNodeProfileId.Qualifier;
44

55
import java.util.ArrayDeque;
66
import java.util.ArrayList;
@@ -64,7 +64,7 @@ public void addNode(AbstractNode node, Stream_ creator) {
6464
addNode(node, creator, creator);
6565
}
6666

67-
public void addNode(AbstractNode node, Stream_ creator, Stream_ parent) {
67+
public void addNode(AbstractNode node, Stream_ creator, @Nullable Stream_ parent) {
6868
reversedNodeList.add(node);
6969
node.addLocationSet(creator.getLocationSet());
7070
nodeCreatorMap.put(node, creator);

core/src/main/java/ai/timefold/solver/core/impl/domain/lookup/ImmutableLookUpStrategy.java renamed to core/src/main/java/ai/timefold/solver/core/impl/domain/common/ImmutableLookupStrategy.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package ai.timefold.solver.core.impl.domain.lookup;
1+
package ai.timefold.solver.core.impl.domain.common;
22

33
import java.util.Map;
44

55
import org.jspecify.annotations.NullMarked;
66

77
@NullMarked
8-
final class ImmutableLookUpStrategy implements LookUpStrategy {
8+
final class ImmutableLookupStrategy implements LookupStrategy {
99

1010
@Override
1111
public void addWorkingObject(Map<Object, Object> idToWorkingObjectMap, Object workingObject) {
@@ -23,10 +23,4 @@ public <E> E lookUpWorkingObject(Map<Object, Object> idToWorkingObjectMap, E ext
2323
return externalObject;
2424
}
2525

26-
@Override
27-
public <E> E lookUpWorkingObjectIfExists(Map<Object, Object> idToWorkingObjectMap, E externalObject) {
28-
// Because it is immutable, we can use the same one.
29-
return externalObject;
30-
}
31-
3226
}

core/src/main/java/ai/timefold/solver/core/impl/domain/lookup/LookUpStrategyType.java renamed to core/src/main/java/ai/timefold/solver/core/impl/domain/common/LookUpStrategyType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ai.timefold.solver.core.impl.domain.lookup;
1+
package ai.timefold.solver.core.impl.domain.common;
22

33
import ai.timefold.solver.core.api.domain.common.PlanningId;
44
import ai.timefold.solver.core.api.domain.entity.PlanningEntity;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package ai.timefold.solver.core.impl.domain.common;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import ai.timefold.solver.core.api.domain.common.Lookup;
7+
import ai.timefold.solver.core.api.domain.common.PlanningId;
8+
9+
import org.jspecify.annotations.NullMarked;
10+
import org.jspecify.annotations.Nullable;
11+
12+
/**
13+
* @see PlanningId
14+
* @see Lookup
15+
*/
16+
@NullMarked
17+
public final class LookupManager
18+
implements Lookup {
19+
20+
private final LookupStrategyResolver lookupStrategyResolver;
21+
private final Map<Object, Object> idToWorkingObjectMap = new HashMap<>();
22+
23+
public LookupManager(LookupStrategyResolver lookupStrategyResolver) {
24+
this.lookupStrategyResolver = lookupStrategyResolver;
25+
}
26+
27+
public void reset() {
28+
idToWorkingObjectMap.clear();
29+
}
30+
31+
public void addWorkingObject(Object workingObject) {
32+
var lookupStrategy = lookupStrategyResolver.determineLookUpStrategy(workingObject);
33+
lookupStrategy.addWorkingObject(idToWorkingObjectMap, workingObject);
34+
}
35+
36+
public void removeWorkingObject(Object workingObject) {
37+
var lookupStrategy = lookupStrategyResolver.determineLookUpStrategy(workingObject);
38+
lookupStrategy.removeWorkingObject(idToWorkingObjectMap, workingObject);
39+
}
40+
41+
@Override
42+
public <E> @Nullable E lookUpWorkingObject(@Nullable E externalObject) {
43+
if (externalObject == null) {
44+
return null;
45+
}
46+
var lookupStrategy = lookupStrategyResolver.determineLookUpStrategy(externalObject);
47+
return lookupStrategy.lookUpWorkingObject(idToWorkingObjectMap, externalObject);
48+
}
49+
50+
}

0 commit comments

Comments
 (0)