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

cucumber.runtime.snippets.ArgumentPattern Maven / Gradle / Ivy

There is a newer version: 7.18.1
Show newest version
package cucumber.runtime.snippets;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ArgumentPattern {

    private final Pattern pattern;
    private final Class type;
    private final String replacement;

    public ArgumentPattern(Pattern pattern, Class type) {
        this(pattern, pattern.pattern(), type);
    }

    public ArgumentPattern(Pattern pattern, String replacement, Class type) {
        this.pattern = pattern;
        this.replacement = replacement;
        this.type = type;
    }

    public Pattern pattern() {
        return pattern;
    }

    public Class type() {
        return type;
    }

    public String replaceMatchesWithGroups(String name) {
        return replaceMatchWith(name, replacement);
    }

    public String replaceMatchesWithSpace(String name) {
        return replaceMatchWith(name, " ");
    }

    private String replaceMatchWith(String name, String replacement) {
        Matcher matcher = pattern.matcher(name);
        String quotedReplacement = Matcher.quoteReplacement(replacement);
        return matcher.replaceAll(quotedReplacement);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy