Skip to content

Commit

Permalink
docs: fix ConstraintCollectors.average() example
Browse files Browse the repository at this point in the history
  • Loading branch information
winklerm authored and triceo committed May 24, 2024
1 parent 8e2e8e8 commit d64b634
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -660,16 +660,16 @@ The sum is collected in an `int`. Variants of this collector:
To calculate the average of a particular property of all elements per group, use the `ConstraintCollectors.average(...)`
collector.
The following code snippet first groups all visits by the vehicle that will be used,
and sums up all the service durations using the `ConstraintCollectors.sum(...)` collector.
and averages all the service durations using the `ConstraintCollectors.average(...)` collector.

[source,java,options="nowrap"]
----
private Constraint totalServiceDuration(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Visit.class)
.groupBy(Visit::getVehicle, sum(Visit::getServiceDuration))
.groupBy(Visit::getVehicle, average(Visit::getServiceDuration))
.penalize(HardSoftScore.ONE_SOFT,
(vehicle, totalServiceDuration) -> totalServiceDuration)
.asConstraint("totalServiceDuration");
(vehicle, averageServiceDuration) -> averageServiceDuration)
.asConstraint("averageServiceDuration");
}
----

Expand Down

0 comments on commit d64b634

Please sign in to comment.