Skip to content

Commit f3528b2

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

119 files changed

Lines changed: 1026 additions & 1058 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 & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
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;
@@ -21,7 +20,8 @@
2120
* To see an example implementation, please refer to the {@link ProblemChange} Javadoc.
2221
*/
2322
@NullMarked
24-
public interface ProblemChangeDirector {
23+
public interface ProblemChangeDirector
24+
extends Lookup {
2525

2626
/**
2727
* Add a new {@link PlanningEntity} instance into the {@link PlanningSolution working solution}.
@@ -35,7 +35,7 @@ public interface ProblemChangeDirector {
3535
/**
3636
* Remove an existing {@link PlanningEntity} instance from the {@link PlanningSolution working solution}.
3737
* Translates the entity to a working planning entity by performing a lookup as defined by
38-
* {@link #lookUpWorkingObjectOrFail(Object)}.
38+
* {@link #lookUpWorkingObject(Object)}.
3939
*
4040
* @param entity the {@link PlanningEntity} instance
4141
* @param entityConsumer removes the working entity from the {@link PlanningSolution working solution}
@@ -45,7 +45,7 @@ public interface ProblemChangeDirector {
4545

4646
/**
4747
* 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)}.
48+
* planning entity by performing a lookup as defined by {@link #lookUpWorkingObject(Object)}.
4949
*
5050
* @param entity the {@link PlanningEntity} instance
5151
* @param variableName name of the {@link PlanningVariable}
@@ -66,7 +66,7 @@ public interface ProblemChangeDirector {
6666

6767
/**
6868
* 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)}.
69+
* to a working problem fact by performing a lookup as defined by {@link #lookUpWorkingObject(Object)}.
7070
*
7171
* @param problemFact the problem fact instance
7272
* @param problemFactConsumer removes the working problem fact from the
@@ -78,7 +78,7 @@ public interface ProblemChangeDirector {
7878
/**
7979
* Change a property of either a {@link PlanningEntity} or a problem fact. Translates the entity or the problem fact
8080
* to its {@link PlanningSolution working solution} counterpart by performing a lookup as defined by
81-
* {@link #lookUpWorkingObjectOrFail(Object)}.
81+
* {@link #lookUpWorkingObject(Object)}.
8282
*
8383
* @param problemFactOrEntity the {@link PlanningEntity} or the problem fact instance
8484
* @param problemFactOrEntityConsumer updates the property of the {@link PlanningEntity}
@@ -88,31 +88,8 @@ public interface ProblemChangeDirector {
8888
<EntityOrProblemFact> void changeProblemProperty(EntityOrProblemFact problemFactOrEntity,
8989
Consumer<EntityOrProblemFact> problemFactOrEntityConsumer);
9090

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);
91+
@Override
92+
<EntityOrProblemFact> @Nullable EntityOrProblemFact lookUpWorkingObject(@Nullable EntityOrProblemFact externalObject);
11693

11794
/**
11895
* Calls variable listeners on the external changes submitted so far.

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/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+
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
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;
6-
import org.jspecify.annotations.Nullable;
76

87
@NullMarked
9-
public sealed interface LookUpStrategy
10-
permits ImmutableLookUpStrategy, NoneLookUpStrategy, PlanningIdLookUpStrategy {
8+
public sealed interface LookupStrategy
9+
permits ImmutableLookupStrategy, NoneLookupStrategy, PlanningIdLookupStrategy {
1110

1211
void addWorkingObject(Map<Object, Object> idToWorkingObjectMap, Object workingObject);
1312

1413
void removeWorkingObject(Map<Object, Object> idToWorkingObjectMap, Object workingObject);
1514

1615
<E> E lookUpWorkingObject(Map<Object, Object> idToWorkingObjectMap, E externalObject);
1716

18-
<E> @Nullable E lookUpWorkingObjectIfExists(Map<Object, Object> idToWorkingObjectMap, E externalObject);
19-
2017
}

0 commit comments

Comments
 (0)