Skip to content

Commit

Permalink
chore: improve ConstraintAnalysis toString
Browse files Browse the repository at this point in the history
  • Loading branch information
triceo committed Dec 10, 2024
1 parent bce2a12 commit ab27eef
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public ConstraintAnalysis(@NonNull ConstraintRef constraintRef, @NonNull Score_
}
}

@NonNull
ConstraintAnalysis<Score_> negate() {
if (matches == null) {
return new ConstraintAnalysis<>(constraintRef, weight.negate(), score.negate(), null, matchCount);
Expand All @@ -72,9 +73,9 @@ ConstraintAnalysis<Score_> negate() {
}
}

static <Score_ extends Score<Score_>> ConstraintAnalysis<Score_> diff(
ConstraintRef constraintRef, ConstraintAnalysis<Score_> constraintAnalysis,
ConstraintAnalysis<Score_> otherConstraintAnalysis) {
static <Score_ extends Score<Score_>> @NonNull ConstraintAnalysis<Score_> diff(
@NonNull ConstraintRef constraintRef, @Nullable ConstraintAnalysis<Score_> constraintAnalysis,
@Nullable ConstraintAnalysis<Score_> otherConstraintAnalysis) {
if (constraintAnalysis == null) {
if (otherConstraintAnalysis == null) {
throw new IllegalStateException(
Expand Down Expand Up @@ -214,10 +215,15 @@ Explanation of score (%s):
@Override
public String toString() {
if (matches == null) {
return "(%s at %s, no matches)"
.formatted(score, weight);
if (matchCount == -1) {
return "(%s at %s, constraint matching disabled)"
.formatted(score, weight);
} else {
return "(%s at %s, %d matches, justifications disabled)"
.formatted(score, weight, matchCount);
}
} else {
return "(%s at %s, %s matches)"
return "(%s at %s, %d matches with justifications)"
.formatted(score, weight, matches.size());
}
}
Expand Down

0 comments on commit ab27eef

Please sign in to comment.