<commit_before>package net.ontopia.presto.spi.utils;

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

import net.ontopia.presto.spi.PrestoTopic;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.ObjectNode;

public class PatternValueUtils {

    public static String getValueByPattern(PrestoVariableResolver variableResolver, Object value, ObjectNode config) {
        if (config != null) {
            JsonNode patternNode = config.path("pattern");
            if (patternNode.isTextual()) {
                String pattern = patternNode.getTextValue();
                return getValueByPattern(variableResolver, value, pattern);
            }
        }
        return null;
    }

    public static String getValueByPattern(PrestoVariableResolver variableResolver, Object value, String pattern) {
        String result = pattern;
        Matcher matcher = Pattern.compile("\\$\\{([\\:\\.\\-\\w]+)\\}").matcher(pattern);
        while (matcher.find()) {
            String variable = matcher.group(1);
            String replacement = getValue(variableResolver, value, variable);
            result = result.replaceFirst("\\$\\{" + variable + "\\}", replacement);
        }<commit_msg>Made method private as it is not used anywhere.<commit_after>package net.ontopia.presto.spi.utils;

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

import net.ontopia.presto.spi.PrestoTopic;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.ObjectNode;

public class PatternValueUtils {

    public static String getValueByPattern(PrestoVariableResolver variableResolver, Object value, ObjectNode config) {
        if (config != null) {
            JsonNode patternNode = config.path("pattern");
            if (patternNode.isTextual()) {
                String pattern = patternNode.getTextValue();
                return getValueByPattern(variableResolver, value, pattern);
            }
        }
        return null;
    }

    private static String getValueByPattern(PrestoVariableResolver variableResolver, Object value, String pattern) {
        String result = pattern;
        Matcher matcher = Pattern.compile("\\$\\{([\\:\\.\\-\\w]+)\\}").matcher(pattern);
        while (matcher.find()) {
            String variable = matcher.group(1);
            String replacement = getValue(variableResolver, value, variable);
            result = result.replaceFirst("\\$\\{" + variable + "\\}", replacement);
        }
{'fraction_non_alphanumeric': 0.12060102807433769, 'fraction_numerical': 0.0007908264136022143, 'mean_word_length': 2.856707317073171, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2564346', 'n_tokens_mistral': 684, 'n_tokens_neox': 663, 'n_words': 152}