Skip to content

Commit

Permalink
Update docs for generator constraint PR (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelCourtney authored Sep 13, 2024
1 parent c429fa9 commit af56de3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions docs/scheduling-and-constraints/procedural/constraints.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,22 @@ class BatteryAboveZero: GeneratorConstraint() {
## Violation Messages

The `Violation` class contains a `message` field, which will display to the user in the UI. It is `null` by default,
but you have two ways to change it.
but you have a few ways to change it.

If you want to set different messages for each violation, you can create the `Violation` objects yourself and then pass
each one individually to `violate(...)` in a generator constraint. Or, if you want to set the same message for all
violations, you can override the `message()` function in the `Constraint` interface. To repeat a previous example:
If you're creating a `Violations` timeline, you can call `violations.withDefaultMessage(message)`, which sets the message
for those in the result that don't already have one.

If you're writing a generator constraint, you can pass it as the last argument to any `violate` call, as in
`violate(listOfViolations, messageForThisBatch)`. Or you can set a constraint-wide default by overriding the
`defaultMessage` method:

<Tabs groupId="lang">
<TabItem value="kt" label="Kotlin">

```kotlin
@ConstraintProcedure
class MyConstraint: GeneratorConstraint() {
override fun message() = "MyActivity cannot start when /my/resource < 0"
override fun defaultMessage() = "MyActivity cannot start when /my/resource < 0"

override fun generate(plan: Plan, simResults: SimulationResults) {
val myResource = simResults.resource("/my/resource", Real.deserializer()).cache()
Expand All @@ -151,7 +154,7 @@ class MyConstraint: GeneratorConstraint() {
@ConstraintProcedure
public class MyConstraint extends GeneratorConstraint {
@Override
public String message() {
public String defaultMessage() {
return "MyActivity cannot start when /my/resource < 0";
}

Expand All @@ -168,3 +171,5 @@ public class MyConstraint extends GeneratorConstraint {

</TabItem>
</Tabs>

The order of precedence is: individual violation messages > batch violation messages > default message.

0 comments on commit af56de3

Please sign in to comment.