io.cucumber.cucumberexpressions.CombinatorialGeneratedExpressionFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cucumber-expressions Show documentation
Show all versions of cucumber-expressions Show documentation
Cucumber Expressions are simple patterns for matching Step Definitions with Gherkin steps
package io.cucumber.cucumberexpressions;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
final class CombinatorialGeneratedExpressionFactory {
// 256 generated expressions ought to be enough for anybody
private static final int MAX_EXPRESSIONS = 256;
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<>();
ArrayDeque> permutation = new ArrayDeque<>(parameterTypeCombinations.size());
generatePermutations(generatedExpressions, permutation);
return generatedExpressions;
}
private void generatePermutations(
List generatedExpressions,
Deque> permutation
) {
if (generatedExpressions.size() >= MAX_EXPRESSIONS) {
return;
}
if (permutation.size() == parameterTypeCombinations.size()) {
ArrayList> permutationCopy = new ArrayList<>(permutation);
generatedExpressions.add(new GeneratedExpression(expressionTemplate, permutationCopy));
return;
}
List> parameterTypes = parameterTypeCombinations.get(permutation.size());
for (ParameterType> parameterType : parameterTypes) {
// Avoid recursion if no elements can be added.
if (generatedExpressions.size() >= MAX_EXPRESSIONS) {
return;
}
permutation.addLast(parameterType);
generatePermutations(generatedExpressions, permutation);
permutation.removeLast();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy