Skip to content

Commit 2072cc6

Browse files
committed
chore: improve ConstraintAnalysis toString
1 parent 3a1ef62 commit 2072cc6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

core/src/main/java/ai/timefold/solver/core/api/score/analysis/ConstraintAnalysis.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public ConstraintAnalysis(@NonNull ConstraintRef constraintRef, @NonNull Score_
6161
}
6262
}
6363

64-
ConstraintAnalysis<Score_> negate() {
64+
@NonNull ConstraintAnalysis<Score_> negate() {
6565
if (matches == null) {
6666
return new ConstraintAnalysis<>(constraintRef, weight.negate(), score.negate(), null, matchCount);
6767
} else {
@@ -72,9 +72,9 @@ ConstraintAnalysis<Score_> negate() {
7272
}
7373
}
7474

75-
static <Score_ extends Score<Score_>> ConstraintAnalysis<Score_> diff(
76-
ConstraintRef constraintRef, ConstraintAnalysis<Score_> constraintAnalysis,
77-
ConstraintAnalysis<Score_> otherConstraintAnalysis) {
75+
static <Score_ extends Score<Score_>> @NonNull ConstraintAnalysis<Score_> diff(
76+
@NonNull ConstraintRef constraintRef, @Nullable ConstraintAnalysis<Score_> constraintAnalysis,
77+
@Nullable ConstraintAnalysis<Score_> otherConstraintAnalysis) {
7878
if (constraintAnalysis == null) {
7979
if (otherConstraintAnalysis == null) {
8080
throw new IllegalStateException(
@@ -214,10 +214,15 @@ Explanation of score (%s):
214214
@Override
215215
public String toString() {
216216
if (matches == null) {
217-
return "(%s at %s, no matches)"
218-
.formatted(score, weight);
217+
if (matchCount == -1) {
218+
return "(%s at %s, constraint matching disabled)"
219+
.formatted(score, weight);
220+
} else {
221+
return "(%s at %s, %d matches, justifications disabled)"
222+
.formatted(score, weight, matchCount);
223+
}
219224
} else {
220-
return "(%s at %s, %s matches)"
225+
return "(%s at %s, %d matches with justifications)"
221226
.formatted(score, weight, matches.size());
222227
}
223228
}

0 commit comments

Comments
 (0)