<commit_before>package com.izettle.wrench.preferences

import android.content.ContentResolver
import android.content.Context
import android.net.Uri
import com.izettle.wrench.core.Bolt
import com.izettle.wrench.core.Nut
import com.izettle.wrench.core.WrenchProviderContract

class WrenchPreferences(context: Context) {
    private val contentResolver: ContentResolver = context.contentResolver

    private fun insertNut(contentResolver: ContentResolver, nut: Nut) {
        contentResolver.insert(WrenchProviderContract.nutUri(), nut.toContentValues())
    }

    private fun getBolt(contentResolver: ContentResolver, key: String): Bolt? {
        val cursor = contentResolver.query(WrenchProviderContract.boltUri(key), null, null, null, null)
        cursor.use {
            if (cursor == null) {
                return null
            }

            if (cursor.moveToFirst()) {
                return Bolt.fromCursor(cursor)
            }
        }

        return Bolt()
    }

    private fun insertBolt(contentResolver: ContentResolver, bolt: Bolt): Uri? {
        return contentResolver.insert(WrenchProviderContract.boltUri(), bolt.toContentValues())
    }

    fun <T : Enum<T>> getEnum(key: String, type: Class<T>, defValue: T): T {
        var bolt = getBolt(contentResolver, key) ?: return defValue<commit_msg>Open WrenchPreferences for testability<commit_after>package com.izettle.wrench.preferences

import android.content.ContentResolver
import android.content.Context
import android.net.Uri
import com.izettle.wrench.core.Bolt
import com.izettle.wrench.core.Nut
import com.izettle.wrench.core.WrenchProviderContract

open class WrenchPreferences(context: Context) {
    private val contentResolver: ContentResolver = context.contentResolver

    private fun insertNut(contentResolver: ContentResolver, nut: Nut) {
        contentResolver.insert(WrenchProviderContract.nutUri(), nut.toContentValues())
    }

    private fun getBolt(contentResolver: ContentResolver, key: String): Bolt? {
        val cursor = contentResolver.query(WrenchProviderContract.boltUri(key), null, null, null, null)
        cursor.use {
            if (cursor == null) {
                return null
            }

            if (cursor.moveToFirst()) {
                return Bolt.fromCursor(cursor)
            }
        }

        return Bolt()
    }

    private fun insertBolt(contentResolver: ContentResolver, bolt: Bolt): Uri? {
        return contentResolver.insert(WrenchProviderContract.boltUri(), bolt.toContentValues())
    }

    fun <T : Enum<T>> getEnum(key: String, type: Class<T>, defValue: T): T {
        var bolt = getBolt(contentResolver, key) ?: return defValue
{'fraction_non_alphanumeric': 0.09715994020926756, 'fraction_numerical': 0.0, 'mean_word_length': 3.2832, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '682368', 'n_tokens_mistral': 758, 'n_tokens_neox': 727, 'n_words': 167}