From c208a157cc98ac1cab06c33b19cc8774c581c035 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 18 Dec 2024 15:53:11 +0100 Subject: [PATCH] docs(spdx-utils): Add comments about the `validChoices()` algorithm While this was partly explained in the commit message that introduced the code, make this more visible. Signed-off-by: Sebastian Schuberth --- utils/spdx/src/main/kotlin/SpdxExpression.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/spdx/src/main/kotlin/SpdxExpression.kt b/utils/spdx/src/main/kotlin/SpdxExpression.kt index bc7f4ec9e6354..45cc29e438a0f 100644 --- a/utils/spdx/src/main/kotlin/SpdxExpression.kt +++ b/utils/spdx/src/main/kotlin/SpdxExpression.kt @@ -300,6 +300,8 @@ class SpdxCompoundExpression( override fun validChoices(): Set = 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() @@ -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 =