Skip to content

Commit 363fba9

Browse files
committed
chore: improve ConstraintAnalysis toString
1 parent 3a1ef62 commit 363fba9

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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

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

64+
@NonNull
6465
ConstraintAnalysis<Score_> negate() {
6566
if (matches == null) {
6667
return new ConstraintAnalysis<>(constraintRef, weight.negate(), score.negate(), null, matchCount);
@@ -72,9 +73,9 @@ ConstraintAnalysis<Score_> negate() {
7273
}
7374
}
7475

75-
static <Score_ extends Score<Score_>> ConstraintAnalysis<Score_> diff(
76-
ConstraintRef constraintRef, ConstraintAnalysis<Score_> constraintAnalysis,
77-
ConstraintAnalysis<Score_> otherConstraintAnalysis) {
76+
static <Score_ extends Score<Score_>> @NonNull ConstraintAnalysis<Score_> diff(
77+
@NonNull ConstraintRef constraintRef, @Nullable ConstraintAnalysis<Score_> constraintAnalysis,
78+
@Nullable ConstraintAnalysis<Score_> otherConstraintAnalysis) {
7879
if (constraintAnalysis == null) {
7980
if (otherConstraintAnalysis == null) {
8081
throw new IllegalStateException(
@@ -214,10 +215,15 @@ Explanation of score (%s):
214215
@Override
215216
public String toString() {
216217
if (matches == null) {
217-
return "(%s at %s, no matches)"
218-
.formatted(score, weight);
218+
if (matchCount == -1) {
219+
return "(%s at %s, constraint matching disabled)"
220+
.formatted(score, weight);
221+
} else {
222+
return "(%s at %s, %d matches, justifications disabled)"
223+
.formatted(score, weight, matchCount);
224+
}
219225
} else {
220-
return "(%s at %s, %s matches)"
226+
return "(%s at %s, %d matches with justifications)"
221227
.formatted(score, weight, matches.size());
222228
}
223229
}

0 commit comments

Comments
 (0)