<commit_before>package org.codejargon.fluentjdbc.api.mapper;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.codejargon.fluentjdbc.internal.mappers.ObjectMapper;
import org.codejargon.fluentjdbc.api.query.Mapper;
import org.codejargon.fluentjdbc.internal.mappers.DefaultObjectMapperRsExtractors;
import org.codejargon.fluentjdbc.internal.support.Maps;

/**
 * <p>Constructs Mappers for mapping a ResultSet row into a plain java object based on object field vs ResultSet column
 * match. Matching is case insensitive and ignore '_' characters. The target class must have
 * a no-arg constructor, fields can be private, no need for accessors.</p>
 *
 * <p>In addition to JDBC types, supports java.time types out of the box. Supports plugins for custom types.</p>
 *
 * @see org.codejargon.fluentjdbc.api.query.Mapper
 */
public class ObjectMappers {
    private final Map<Class, ObjectMapperRsExtractor> extractors;
    private final Map<Class, Mapper<?>> mappers;

    private ObjectMappers(Map<Class, ObjectMapperRsExtractor> extractors) {
        this.extractors = Maps.merge(DefaultObjectMapperRsExtractors.extractors(), extractors);
        mappers = new ConcurrentHashMap<>();
    }

    @SuppressWarnings("unchecked")
    public <T> Mapper<T> forClass(Class<T> clazz) {
        if(!mappers.containsKey(clazz)) {
            mappers.put(clazz, new ObjectMapper<>(clazz, extractors));
        }
        return (Mapper<T>) mappers.get(clazz);
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public static class Builder {
        private Map<Class, ObjectMapperRsExtractor> extractors = Maps.copyOf(new HashMap<>());
        
        private Builder() {
            
        }

        /**
         * Sets converters to support custom (non-JDBC) fields.
         * @param extractors Map of field class / ResultSet extractors
         * @return this
         */
        public Builder converters(Map<Class, ObjectMapperRsExtractor> extractors) {
            this.extractors = Maps.copyOf(extractors);<commit_msg>consistent naming - slight api change<commit_after>package org.codejargon.fluentjdbc.api.mapper;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.codejargon.fluentjdbc.internal.mappers.ObjectMapper;
import org.codejargon.fluentjdbc.api.query.Mapper;
import org.codejargon.fluentjdbc.internal.mappers.DefaultObjectMapperRsExtractors;
import org.codejargon.fluentjdbc.internal.support.Maps;

/**
 * <p>Constructs Mappers for mapping a ResultSet row into a plain java object based on object field vs ResultSet column
 * match. Matching is case insensitive and ignore '_' characters. The target class must have
 * a no-arg constructor, fields can be private, no need for accessors.</p>
 *
 * <p>In addition to JDBC types, supports java.time types out of the box. Supports plugins for custom types.</p>
 *
 * @see org.codejargon.fluentjdbc.api.query.Mapper
 */
public class ObjectMappers {
    private final Map<Class, ObjectMapperRsExtractor> extractors;
    private final Map<Class, Mapper<?>> mappers;

    private ObjectMappers(Map<Class, ObjectMapperRsExtractor> extractors) {
        this.extractors = Maps.merge(DefaultObjectMapperRsExtractors.extractors(), extractors);
        mappers = new ConcurrentHashMap<>();
    }

    @SuppressWarnings("unchecked")
    public <T> Mapper<T> forClass(Class<T> clazz) {
        if(!mappers.containsKey(clazz)) {
            mappers.put(clazz, new ObjectMapper<>(clazz, extractors));
        }
        return (Mapper<T>) mappers.get(clazz);
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public static class Builder {
        private Map<Class, ObjectMapperRsExtractor> extractors = Maps.copyOf(new HashMap<>());
        
        private Builder() {
            
        }

        /**
         * Sets extractors to support custom (non-JDBC) fields.
         * @param extractors Map of field class / ResultSet extractors
         * @return this
         */
        public Builder extractors(Map<Class, ObjectMapperRsExtractor> extractors) {
            this.extractors = Maps.copyOf(extractors);
{'fraction_non_alphanumeric': 0.09835680751173709, 'fraction_numerical': 0.0, 'mean_word_length': 3.361310133060389, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '143146', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1231, 'n_words': 319}