io.cucumber.cucumberexpressions.CombinatorialGeneratedExpressionFactory Maven / Gradle / Ivy
package io.cucumber.cucumberexpressions;
import java.util.ArrayList;
import java.util.List;
class CombinatorialGeneratedExpressionFactory {
private final String expressionTemplate;
private final List>> parameterTypeCombinations;
CombinatorialGeneratedExpressionFactory(
String expressionTemplate,
List>> parameterTypeCombinations) {
this.expressionTemplate = expressionTemplate;
this.parameterTypeCombinations = parameterTypeCombinations;
}
List generateExpressions() {
List generatedExpressions = new ArrayList<>();
generatePermutations(generatedExpressions, 0, new ArrayList>());
return generatedExpressions;
}
private void generatePermutations(
List generatedExpressions,
int depth,
List> currentParameterTypes
) {
if (depth == parameterTypeCombinations.size()) {
generatedExpressions.add(new GeneratedExpression(expressionTemplate, currentParameterTypes));
return;
}
for (int i = 0; i < parameterTypeCombinations.get(depth).size(); ++i) {
List> newCurrentParameterTypes = new ArrayList<>(currentParameterTypes); // clone
newCurrentParameterTypes.add(parameterTypeCombinations.get(depth).get(i));
generatePermutations(
generatedExpressions,
depth + 1,
newCurrentParameterTypes
);
}
}
}