Record Class ScoreAnalysis<Score_ extends Score<Score_>>
- Type Parameters:
Score_-- Record Components:
constraintMap- for each constraint identified by itsConstraint.getConstraintRef(), theConstraintAnalysisthat describes the impact of that constraint on the overall score. Constraints are present even if they have no matches, unless their weight is zero; zero-weight constraints are not present. Entries in the map have a stable iteration order; items are ordered first byConstraintAnalysis.weight(), then byConstraintAnalysis.constraintRef().
Score into individual ConstraintAnalysis instances,
one for each constraint.
Compared to ScoreExplanation, this is JSON-friendly and faster to generate.
In order to be fully serializable to JSON, MatchAnalysis instances must be serializable to JSON
and that requires any implementations of ConstraintJustification to be serializable to JSON.
This is the responsibility of the user.
For deserialization from JSON, the user needs to provide the deserializer themselves.
This is due to the fact that, once the ScoreAnalysis is received over the wire,
we no longer know which Score type or ConstraintJustification type was used.
The user has all of that information in their domain model,
and so they are the correct party to provide the deserializer.
Note: the constructors of this record are off-limits.
We ask users to use exclusively SolutionManager.analyze(Object) to obtain instances of this record.
-
Constructor Summary
ConstructorsConstructorDescriptionScoreAnalysis(@NonNull Score_ score, @NonNull Map<ConstraintRef, ConstraintAnalysis<Score_>> constraintMap) Creates an instance of aScoreAnalysisrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns individualConstraintAnalysisinstances that make up thisScoreAnalysis.@NonNull Map<ConstraintRef,ConstraintAnalysis<Score_>> Returns the value of theconstraintMaprecord component.@NonNull ScoreAnalysis<Score_>diff(@NonNull ScoreAnalysis<Score_> other) Compare thisScoreAnalysisto anotherScoreAnalysisand retrieve the difference between them.final booleanIndicates whether some other object is "equal to" this one.@Nullable ConstraintAnalysis<Score_>getConstraintAnalysis(@NonNull ConstraintRef constraintRef) Performs a lookup onconstraintMap().@Nullable ConstraintAnalysis<Score_>getConstraintAnalysis(@NonNull String constraintName) As defined bygetConstraintAnalysis(ConstraintRef).@Nullable ConstraintAnalysis<Score_>getConstraintAnalysis(@NonNull String constraintPackage, @NonNull String constraintName) Deprecated, for removal: This API element is subject to removal in a future version.final inthashCode()Returns a hash code value for this object.boolean@NonNull Score_score()Returns the value of thescorerecord component.@NonNull StringReturns a diagnostic text that explains the solution through theConstraintAnalysisAPI to identify which constraints cause that score quality.toString()Returns a string representation of this record class.
-
Constructor Details
-
ScoreAnalysis
public ScoreAnalysis(@NonNull Score_ score, @NonNull Map<ConstraintRef, ConstraintAnalysis<Score_>> constraintMap) Creates an instance of aScoreAnalysisrecord class.- Parameters:
score- the value for thescorerecord componentconstraintMap- the value for theconstraintMaprecord component
-
-
Method Details
-
getConstraintAnalysis
public @Nullable ConstraintAnalysis<Score_> getConstraintAnalysis(@NonNull ConstraintRef constraintRef) Performs a lookup onconstraintMap(). Equivalent toconstraintMap().get(constraintRef).- Returns:
- null if no constraint matches of such constraint are present
-
getConstraintAnalysis
@Deprecated(forRemoval=true, since="1.13.0") public @Nullable ConstraintAnalysis<Score_> getConstraintAnalysis(@NonNull String constraintPackage, @NonNull String constraintName) Deprecated, for removal: This API element is subject to removal in a future version.UsegetConstraintAnalysis(String)instead.As defined bygetConstraintAnalysis(ConstraintRef)where the arguments are first composed into a singular constraint ID.- Returns:
- null if no constraint matches of such constraint are present
-
getConstraintAnalysis
As defined bygetConstraintAnalysis(ConstraintRef).- Returns:
- null if no constraint matches of such constraint are present
- Throws:
IllegalStateException- if multiple constraints with the same name are present, which is possible if they are in different constraint packages. Constraint packages are deprecated, we recommend avoiding them and instead naming constraints uniquely. If you must use constraint packages, seegetConstraintAnalysis(String, String)(also deprecated) and reach out to us to discuss your use case.
-
diff
Compare thisScoreAnalysisto anotherScoreAnalysisand retrieve the difference between them. The comparison is in the direction ofthis - other.Example: if
thishas a score of 100 andotherhas a score of 90, the returnedscorewill be 10. If this and other were inverted, the score would have been -10. The same applies to all other properties ofScoreAnalysis.In order to properly diff
MatchAnalysisagainst each other, we rely on the user implementingConstraintJustificationequality correctly. In other words, the diff will consider two justifications equal if the user says they are equal, and it expects the hash code to be consistent with equals.If one
ScoreAnalysisprovidesMatchAnalysisand the other doesn't, exception is thrown. SuchScoreAnalysisinstances are mutually incompatible. -
constraintAnalyses
Returns individualConstraintAnalysisinstances that make up thisScoreAnalysis.- Returns:
- equivalent to
constraintMap().values()
-
summarize
Returns a diagnostic text that explains the solution through theConstraintAnalysisAPI to identify which constraints cause that score quality. The string is built fresh every time the method is called.In case of an
infeasiblesolution, this can help diagnose the cause of that.Do not parse the return value, its format may change without warning. Instead, provide this information in a UI or a service, use
constraintAnalyses()and convert those into a domain-specific API. -
isSolutionInitialized
public boolean isSolutionInitialized() -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
score
Returns the value of thescorerecord component.- Returns:
- the value of the
scorerecord component
-
constraintMap
Returns the value of theconstraintMaprecord component.- Returns:
- the value of the
constraintMaprecord component
-
getConstraintAnalysis(String)instead.