<commit_before>package com.keijack.orm.sqlfile;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.keijack.orm.sqlfile.annotations.Entity;

enum StamentPreparer {
    INSTANCE;

    private static final int READ_FILE_BUFF_SIZE = 512;

    public SqlAndParams prepare(Class<?> clazz, Map<String, Object> parameters) throws IOException {

	String sqlTemplate = getSqlTemplate(clazz);
	Map<String, Object> model = ignoreNullValue(parameters);

	List<String> requiredTags = getRequiredTags(sqlTemplate);
	checkRequriedTags(requiredTags, model);

	List<String> validRows = getValidRows(sqlTemplate, model);

	List<Object> params = new ArrayList<>(model.size());
	List<String> rows = replaceAllTags(validRows, model, params);

	String sql = join(rows);

	SqlAndParams stamentPreparer = new SqlAndParams();
	stamentPreparer.setSql(formatSql(sql));
	stamentPreparer.setCountSql(formatSql(getCountSql(sql)));
	stamentPreparer.setParams(params);

	return stamentPreparer;
    }

    private Map<String, Object> ignoreNullValue(Map<String, Object> parameters) {
	Map<String, Object> model = new HashMap<>(parameters.size());
	for (String key : parameters.keySet()) {
	    Object val = parameters.get(key);
	    if (val != null) {
		model.put(key, val);
	    }
	}
	return model;
    }

    private String formatSql(String sql) {
	return sql.replaceAll("--[^\\n]*", "")
		.replaceAll("\\/\\*(?:\\s|.)*?\\*\\/", "")
		.replaceAll("\\s+", " ");

    }

    private String getCountSql(String sql) {
	Matcher matcher = Pattern.compile("--#(count\\([^\\n]*)").matcher(sql);
	String countSelect;
	if (matcher.find()) {
	    countSelect = matcher.group(1);
	} else {
	    countSelect = "count(*)";
	}<commit_msg>trim sql in format sql method.<commit_after>package com.keijack.orm.sqlfile;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.keijack.orm.sqlfile.annotations.Entity;

enum StamentPreparer {
    INSTANCE;

    private static final int READ_FILE_BUFF_SIZE = 512;

    public SqlAndParams prepare(Class<?> clazz, Map<String, Object> parameters) throws IOException {

	String sqlTemplate = getSqlTemplate(clazz);
	Map<String, Object> model = ignoreNullValue(parameters);

	List<String> requiredTags = getRequiredTags(sqlTemplate);
	checkRequriedTags(requiredTags, model);

	List<String> validRows = getValidRows(sqlTemplate, model);

	List<Object> params = new ArrayList<>(model.size());
	List<String> rows = replaceAllTags(validRows, model, params);

	String sql = join(rows);

	SqlAndParams stamentPreparer = new SqlAndParams();
	stamentPreparer.setSql(formatSql(sql));
	stamentPreparer.setCountSql(formatSql(getCountSql(sql)));
	stamentPreparer.setParams(params);

	return stamentPreparer;
    }

    private Map<String, Object> ignoreNullValue(Map<String, Object> parameters) {
	Map<String, Object> model = new HashMap<>(parameters.size());
	for (String key : parameters.keySet()) {
	    Object val = parameters.get(key);
	    if (val != null) {
		model.put(key, val);
	    }
	}
	return model;
    }

    private String formatSql(String sql) {
	return sql.replaceAll("--[^\\n]*", "")
		.replaceAll("\\/\\*(?:\\s|.)*?\\*\\/", "")
		.replaceAll("\\s+", " ").trim();

    }

    private String getCountSql(String sql) {
	Matcher matcher = Pattern.compile("--#(count\\([^\\n]*)").matcher(sql);
	String countSelect;
	if (matcher.find()) {
	    countSelect = matcher.group(1);
	} else {
	    countSelect = "count(*)";
	}
{'fraction_non_alphanumeric': 0.1476833976833977, 'fraction_numerical': 0.0019305019305019305, 'mean_word_length': 4.772980501392758, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '4261980', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1319, 'n_words': 278}