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

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

There is a newer version: 17.1.0
Show newest version
package io.cucumber.cucumberexpressions;

public class SingleTransformer implements Transformer {
    private final Function function;

    public SingleTransformer(Function function) {
        this.function = function;
    }

    @Override
    public T transform(String... groupValues) {
        if (groupValues == null) return null;
        String arg = null;
        for (String groupValue : groupValues) {
            if (groupValue != null) {
                if (arg != null)
                    throw new CucumberExpressionException(String.format("Single transformer unexpectedly matched 2 values - \"%s\" and \"%s\"", arg, groupValue));
                arg = groupValue;
            }
        }
        if (arg == null) return null;
        return function.apply(arg);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy