Skip to content

Commit

Permalink
docs(spdx-utils): Add comments about the validChoices() algorithm
Browse files Browse the repository at this point in the history
While this was partly explained in the commit message that introduced the
code, make this more visible.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Dec 18, 2024
1 parent acf9415 commit c208a15
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion utils/spdx/src/main/kotlin/SpdxExpression.kt
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ class SpdxCompoundExpression(
override fun validChoices(): Set<SpdxExpression> =
when (operator) {
SpdxOperator.AND -> {
// If there is a top-level `AND` in an expression, create the combinations of all choices on the left
// and all choices on the right to get the overall valid choices.
children.fold(setOf()) { acc, child ->
if (acc.isEmpty()) {
child.validChoices()
Expand All @@ -317,7 +319,11 @@ class SpdxCompoundExpression(
}
}

SpdxOperator.OR -> children.flatMapTo(mutableSetOf()) { it.validChoices() }
SpdxOperator.OR -> {
// If there is a top-level `OR` in an expression, the operands already are the choices and just need to
// be checked themselves for choices.
children.flatMapTo(mutableSetOf()) { it.validChoices() }
}
}

override fun offersChoice(): Boolean =
Expand Down

0 comments on commit c208a15

Please sign in to comment.