<commit_before>package com.wizzardo.http.framework.template;

import com.wizzardo.tools.evaluation.EvalTools;
import com.wizzardo.tools.evaluation.Expression;
import com.wizzardo.tools.misc.Unchecked;

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

/**
 * @author: moxa
 * Date: 2/11/13
 */
public class ExpressionHolder<T> implements Renderable {
    private volatile boolean prepared = false;
    private String string;
    private Expression expression;
    protected boolean stringTemplate;
    protected List<String> imports;

    public ExpressionHolder(String s) {
        this(s, null, false);
    }

    public ExpressionHolder(String s, List<String> imports, boolean stringTemplate) {
        string = s;
        this.imports = imports;
        this.stringTemplate = stringTemplate;
    }

    protected ExpressionHolder() {
    }

    public RenderResult get(Map<String, Object> model) {
        return new RenderResult(String.valueOf(getRaw(model)));
    }

    private static Pattern p = Pattern.compile("\\$\\{([^\\{\\}]+)\\}|\\$([^\\., -]+)|(\\[.+\\])");

    public T getRaw(Map<String, Object> model) {
        if (!prepared) {
            synchronized (this) {
                if (!prepared) {
                    Unchecked.run(() -> {
                        if (stringTemplate)
                            expression = EvalTools.prepare(string, model, TagLib.getTagFunctions(), imports, true);
                        else {
                            Matcher m = p.matcher(string);
                            if (m.matches()) {
                                String exp = m.group(1);
                                if (exp == null) {
                                    exp = m.group(2);
                                }
                                if (exp == null) {
                                    exp = m.group(3);
                                }
                                expression = EvalTools.prepare(exp, model, TagLib.getTagFunctions(), imports);
                            } else
                                expression = EvalTools.prepare(string, model, TagLib.getTagFunctions(), imports);
                        }
                    });
                    prepared = true;
                }
            }
        }<commit_msg>minor change<commit_after>package com.wizzardo.http.framework.template;

import com.wizzardo.tools.evaluation.EvalTools;
import com.wizzardo.tools.evaluation.Expression;
import com.wizzardo.tools.misc.Unchecked;

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

/**
 * @author: moxa
 * Date: 2/11/13
 */
public class ExpressionHolder<T> implements Renderable {
    private volatile boolean prepared = false;
    private String string;
    private Expression expression;
    protected boolean stringTemplate;
    protected List<String> imports;

    public ExpressionHolder(String s) {
        this(s, null, false);
    }

    public ExpressionHolder(String s, List<String> imports, boolean stringTemplate) {
        string = s;
        this.imports = imports;
        this.stringTemplate = stringTemplate;
    }

    protected ExpressionHolder() {
    }

    public RenderResult get(Map<String, Object> model) {
        return new RenderResult(String.valueOf(getRaw(model)));
    }

    private static Pattern p = Pattern.compile("\\$\\{([^\\{\\}]+)\\}|\\$([^\\., -]+)|(\\[.+\\])");

    public T raw(Map<String, Object> model) {
        return getRaw(model);
    }
    
    public T getRaw(Map<String, Object> model) {
        if (!prepared) {
            synchronized (this) {
                if (!prepared) {
                    Unchecked.run(() -> {
                        if (stringTemplate)
                            expression = EvalTools.prepare(string, model, TagLib.getTagFunctions(), imports, true);
                        else {
                            Matcher m = p.matcher(string);
                            if (m.matches()) {
                                String exp = m.group(1);
                                if (exp == null) {
                                    exp = m.group(2);
                                }
                                if (exp == null) {
                                    exp = m.group(3);
                                }
                                expression = EvalTools.prepare(exp, model, TagLib.getTagFunctions(), imports);
                            } else
                                expression = EvalTools.prepare(string, model, TagLib.getTagFunctions(), imports);
                        }
                    });
                    prepared = true;
                }
            }
        }
{'fraction_non_alphanumeric': 0.11371237458193979, 'fraction_numerical': 0.0033444816053511705, 'mean_word_length': 1.4363543788187372, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5219137', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1174, 'n_words': 264}