Skip to content

Commit cf91fa5

Browse files
committed
Review
1 parent 514dddb commit cf91fa5

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

core/src/main/java/ai/timefold/solver/core/impl/score/stream/common/inliner/BigDecimalWeightedScoreImpacter.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
import ai.timefold.solver.core.api.score.Score;
77

8+
import org.jspecify.annotations.NullMarked;
9+
import org.jspecify.annotations.Nullable;
10+
11+
@NullMarked
812
final class BigDecimalWeightedScoreImpacter<Score_ extends Score<Score_>, Context_ extends ScoreContext<Score_, ?>>
913
implements WeightedScoreImpacter<Score_, Context_> {
1014

@@ -17,19 +21,21 @@ public BigDecimalWeightedScoreImpacter(BigDecimalImpactFunction<Score_, Context_
1721
}
1822

1923
@Override
20-
public ScoreImpact<Score_> impactScore(int matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
24+
public ScoreImpact<Score_> impactScore(int matchWeight, @Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
2125
context.getConstraint().assertCorrectImpact(matchWeight);
2226
return impactFunction.impact(context, BigDecimal.valueOf(matchWeight), constraintMatchSupplier);
2327
}
2428

2529
@Override
26-
public ScoreImpact<Score_> impactScore(long matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
30+
public ScoreImpact<Score_> impactScore(long matchWeight,
31+
@Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
2732
context.getConstraint().assertCorrectImpact(matchWeight);
2833
return impactFunction.impact(context, BigDecimal.valueOf(matchWeight), constraintMatchSupplier);
2934
}
3035

3136
@Override
32-
public ScoreImpact<Score_> impactScore(BigDecimal matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
37+
public ScoreImpact<Score_> impactScore(BigDecimal matchWeight,
38+
@Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
3339
context.getConstraint().assertCorrectImpact(matchWeight);
3440
return impactFunction.impact(context, matchWeight, constraintMatchSupplier);
3541
}

core/src/main/java/ai/timefold/solver/core/impl/score/stream/common/inliner/IntWeightedScoreImpacter.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
import ai.timefold.solver.core.api.score.Score;
77

8+
import org.jspecify.annotations.NullMarked;
9+
import org.jspecify.annotations.Nullable;
10+
11+
@NullMarked
812
final class IntWeightedScoreImpacter<Score_ extends Score<Score_>, Context_ extends ScoreContext<Score_, ?>>
913
implements WeightedScoreImpacter<Score_, Context_> {
1014

@@ -17,18 +21,20 @@ public IntWeightedScoreImpacter(IntImpactFunction<Score_, Context_> impactFuncti
1721
}
1822

1923
@Override
20-
public ScoreImpact<Score_> impactScore(int matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
24+
public ScoreImpact<Score_> impactScore(int matchWeight, @Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
2125
context.getConstraint().assertCorrectImpact(matchWeight);
2226
return impactFunction.impact(context, matchWeight, constraintMatchSupplier);
2327
}
2428

2529
@Override
26-
public ScoreImpact<Score_> impactScore(long matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
30+
public ScoreImpact<Score_> impactScore(long matchWeight,
31+
@Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
2732
throw new UnsupportedOperationException("Impossible state: passing long into an int impacter.");
2833
}
2934

3035
@Override
31-
public ScoreImpact<Score_> impactScore(BigDecimal matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
36+
public ScoreImpact<Score_> impactScore(BigDecimal matchWeight,
37+
@Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
3238
throw new UnsupportedOperationException("Impossible state: passing BigDecimal into an int impacter.");
3339
}
3440

core/src/main/java/ai/timefold/solver/core/impl/score/stream/common/inliner/LongWeightedScoreImpacter.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
import ai.timefold.solver.core.api.score.Score;
77

8+
import org.jspecify.annotations.NullMarked;
9+
import org.jspecify.annotations.Nullable;
10+
11+
@NullMarked
812
final class LongWeightedScoreImpacter<Score_ extends Score<Score_>, Context_ extends ScoreContext<Score_, ?>>
913
implements WeightedScoreImpacter<Score_, Context_> {
1014

@@ -17,19 +21,21 @@ public LongWeightedScoreImpacter(LongImpactFunction<Score_, Context_> impactFunc
1721
}
1822

1923
@Override
20-
public ScoreImpact<Score_> impactScore(int matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
24+
public ScoreImpact<Score_> impactScore(int matchWeight, @Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
2125
context.getConstraint().assertCorrectImpact(matchWeight);
2226
return impactFunction.impact(context, matchWeight, constraintMatchSupplier); // int can be cast to long
2327
}
2428

2529
@Override
26-
public ScoreImpact<Score_> impactScore(long matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
30+
public ScoreImpact<Score_> impactScore(long matchWeight,
31+
@Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
2732
context.getConstraint().assertCorrectImpact(matchWeight);
2833
return impactFunction.impact(context, matchWeight, constraintMatchSupplier);
2934
}
3035

3136
@Override
32-
public ScoreImpact<Score_> impactScore(BigDecimal matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
37+
public ScoreImpact<Score_> impactScore(BigDecimal matchWeight,
38+
@Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier) {
3339
throw new UnsupportedOperationException("Impossible state: passing BigDecimal into a long impacter.");
3440
}
3541

core/src/main/java/ai/timefold/solver/core/impl/score/stream/common/inliner/WeightedScoreImpacter.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import ai.timefold.solver.core.api.score.Score;
66

7+
import org.jspecify.annotations.NullMarked;
8+
import org.jspecify.annotations.Nullable;
9+
710
/**
811
* There are several valid ways how an impacter could be called from a constraint stream:
912
*
@@ -21,6 +24,7 @@
2124
* for the method types it doesn't support. The CS API guarantees no types are mixed. For example,
2225
* a {@link BigDecimal} parameter method won't be called on an instance built with an {@link IntImpactFunction}.
2326
*/
27+
@NullMarked
2428
public interface WeightedScoreImpacter<Score_ extends Score<Score_>, Context_ extends ScoreContext<Score_, ?>> {
2529

2630
static <Score_ extends Score<Score_>, Context_ extends ScoreContext<Score_, ?>> WeightedScoreImpacter<Score_, Context_>
@@ -40,46 +44,51 @@ public interface WeightedScoreImpacter<Score_ extends Score<Score_>, Context_ ex
4044

4145
/**
4246
* @param matchWeight never null
43-
* @param constraintMatchSupplier ignored unless constraint match enableds
47+
* @param constraintMatchSupplier ignored unless constraint match enabled
4448
* @return never null
4549
*/
46-
ScoreImpact<Score_> impactScore(int matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier);
50+
ScoreImpact<Score_> impactScore(int matchWeight, @Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier);
4751

4852
/**
4953
* @param matchWeight never null
5054
* @param constraintMatchSupplier ignored unless constraint match enabled
5155
* @return never null
5256
*/
53-
ScoreImpact<Score_> impactScore(long matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier);
57+
ScoreImpact<Score_> impactScore(long matchWeight, @Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier);
5458

5559
/**
5660
* @param matchWeight never null
5761
* @param constraintMatchSupplier ignored unless constraint match enabled
5862
* @return never null
5963
*/
60-
ScoreImpact<Score_> impactScore(BigDecimal matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier);
64+
ScoreImpact<Score_> impactScore(BigDecimal matchWeight, @Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier);
6165

6266
Context_ getContext();
6367

68+
@NullMarked
6469
@FunctionalInterface
6570
interface IntImpactFunction<Score_ extends Score<Score_>, Context_ extends ScoreContext<Score_, ?>> {
6671

67-
ScoreImpact<Score_> impact(Context_ context, int matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier);
72+
ScoreImpact<Score_> impact(Context_ context, int matchWeight,
73+
@Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier);
6874

6975
}
7076

77+
@NullMarked
7178
@FunctionalInterface
7279
interface LongImpactFunction<Score_ extends Score<Score_>, Context_ extends ScoreContext<Score_, ?>> {
7380

74-
ScoreImpact<Score_> impact(Context_ context, long matchWeight, ConstraintMatchSupplier<Score_> constraintMatchSupplier);
81+
ScoreImpact<Score_> impact(Context_ context, long matchWeight,
82+
@Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier);
7583

7684
}
7785

86+
@NullMarked
7887
@FunctionalInterface
7988
interface BigDecimalImpactFunction<Score_ extends Score<Score_>, Context_ extends ScoreContext<Score_, ?>> {
8089

8190
ScoreImpact<Score_> impact(Context_ context, BigDecimal matchWeight,
82-
ConstraintMatchSupplier<Score_> constraintMatchSupplier);
91+
@Nullable ConstraintMatchSupplier<Score_> constraintMatchSupplier);
8392

8493
}
8594

0 commit comments

Comments
 (0)