<commit_before>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jdbi.v3.core.statement;

import java.text.MessageFormat;
import java.util.AbstractMap;
import java.util.Comparator;
import java.util.Set;

/**
 * Uses {@link MessageFormat#format} as a template engine.
 *
 * You must use "0", "1", "2", etc as keys. You may {@link org.jdbi.v3.core.config.Configurable#define} values in any order.
 *
 * Start at 0, increment by 1, do not repeat any keys, and do not exceed the maximum array size for your system. Leading zeroes are ignored. Invalid keys will trigger an {@link IllegalArgumentException} when {@link #render} is called.
 *
 * MessageFormat does not throw exceptions when your pattern string's placeholders don't match the values, and neither does this class. This class only validates your keys in order to reliably reconstruct the values array. It does not validate the pattern string or values.
 *
 * Example usage:
 * <pre>{@code
 *     // select bar from foo where col = 'abc'
 *     jdbi.useHandle(handle -> handle.createCall("select {1} from {0} where col = ''{2}''")
 *         .setTemplateEngine(MessageFormatTemplateEngine.INSTANCE)
 *         .define("0", "foo")
 *         .define("1", "bar")
 *         .define("2", "abc")
 *         .invoke());
 * }</pre>
 */
public enum MessageFormatTemplateEngine implements TemplateEngine {
    INSTANCE;

    @Override
    public String render(String template, StatementContext ctx) {
        validateKeys(ctx.getAttributes().keySet());

        Object[] args = ctx.getAttributes()
            .entrySet()
            .stream()
            .map(x -> new AbstractMap.SimpleImmutableEntry<>(Integer.valueOf(x.getKey()), x.getValue()))<commit_msg>javadoc<commit_after>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jdbi.v3.core.statement;

import java.text.MessageFormat;
import java.util.AbstractMap;
import java.util.Comparator;
import java.util.Set;

/**
 * Uses {@link MessageFormat#format(String, Object...)} as a template engine.
 *
 * You must use "0", "1", "2", etc as keys. You may {@link org.jdbi.v3.core.config.Configurable#define(String, Object)} values in any order.
 *
 * Start at 0, increment by 1, do not repeat any keys, and do not exceed the maximum array size for your system. Leading zeroes are ignored. Invalid keys will trigger an {@link IllegalArgumentException} (or subclasses such as {@link NumberFormatException}) when {@link #render(String, StatementContext)} is called.
 *
 * MessageFormat does not throw exceptions when your pattern string's placeholders don't match the values, and neither does this class. This class only validates your keys in order to reliably reconstruct the values array. It does not validate the pattern string or values.
 *
 * Example usage:
 * <pre>{@code
 *     // select bar from foo where col = 'abc'
 *     jdbi.useHandle(handle -> handle.createCall("select {1} from {0} where col = ''{2}''")
 *         .setTemplateEngine(MessageFormatTemplateEngine.INSTANCE)
 *         .define("0", "foo")
 *         .define("1", "bar")
 *         .define("2", "abc")
 *         .invoke());
 * }</pre>
 */
public enum MessageFormatTemplateEngine implements TemplateEngine {
    INSTANCE;

    @Override
    public String render(String template, StatementContext ctx) {
        validateKeys(ctx.getAttributes().keySet());

        Object[] args = ctx.getAttributes()
            .entrySet()
            .stream()
            .map(x -> new AbstractMap.SimpleImmutableEntry<>(Integer.valueOf(x.getKey()), x.getValue()))
{'fraction_non_alphanumeric': 0.10930996714129244, 'fraction_numerical': 0.007447973713033954, 'mean_word_length': 3.5614385614385613, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5939067', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1203, 'n_words': 494}