All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cucumber.cucumberexpressions.CombinatorialGeneratedExpressionFactory Maven / Gradle / Ivy

There is a newer version: 17.1.0
Show newest version
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
            );
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy