io.cucumber.cucumberexpressions.SingleTransformer Maven / Gradle / Ivy
package io.cucumber.cucumberexpressions;
import java.util.function.Function;
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);
}
}