<commit_before>package com.jayrave.moshi.pristineModels

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.reflect.KProperty1

abstract class Mapper<T : Any>(
        private val nameFormatter: NameFormatter = CamelCaseToSnakeCaseFormatter()) {

    private var jsonAdapter: JsonAdapter<T>? = null
    private val jsonAdapterBuilt = AtomicBoolean(false)
    private val fieldMappings = LinkedHashMap<String, FieldMappingImpl<T, *>>()

    fun <F> field(
            property: KProperty1<T, F>, name: String = nameFormatter.format(property.name)):
            FieldMapping<T, F> {

        return when (jsonAdapterBuilt.get()) {
            true -> throw IllegalStateException("Trying to add a field mapping too late")
            else -> {
                val fieldMapping = FieldMappingImpl(name, property)<commit_msg>Mapper#field now allows using custom json adapters for fields<commit_after>package com.jayrave.moshi.pristineModels

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.reflect.KProperty1

abstract class Mapper<T : Any>(
        private val nameFormatter: NameFormatter = CamelCaseToSnakeCaseFormatter()) {

    private var jsonAdapter: JsonAdapter<T>? = null
    private val jsonAdapterBuilt = AtomicBoolean(false)
    private val fieldMappings = LinkedHashMap<String, FieldMappingImpl<T, *>>()

    /**
     * @param [property] this field corresponds to
     * @param [name] of the JSON field. If `null`, name formatter is used to format
     * property name into field name
     * @param [jsonAdapter] to be used to map this field from/to JSON. If `null`, whatever
     * [Moshi] provides is used
     */
    fun <F> field(
            property: KProperty1<T, F>, name: String = nameFormatter.format(property.name),
            jsonAdapter: JsonAdapter<F>? = null):
            FieldMapping<T, F> {

        return when (jsonAdapterBuilt.get()) {
            true -> throw IllegalStateException("Trying to add a field mapping too late")
            else -> {
                val fieldMapping = FieldMappingImpl(name, property, jsonAdapter)
{'fraction_non_alphanumeric': 0.09373703857320614, 'fraction_numerical': 0.0016590626296142678, 'mean_word_length': 3.508411214953271, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 22, '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': '4041544', 'n_tokens_mistral': 675, 'n_tokens_neox': 663, 'n_words': 190}