<commit_before>package jp.toastkid.yobidashi.search.suggestion

import android.net.Uri
import jp.toastkid.yobidashi.libs.Strings
import jp.toastkid.yobidashi.libs.network.HttpClientFactory
import okhttp3.Call
import okhttp3.Callback
import okhttp3.Request
import okhttp3.Response
import timber.log.Timber
import java.io.IOException
import java.util.*

/**
 * Suggest Web API response fetcher.
 *
 * @author toastkidjp
 */
class SuggestionFetcher {

    /**
     * HTTP client.
     */
    private val httpClient = HttpClientFactory.withTimeout(3L)

    /**
     * Fetch Web API result asynchronously.
     *
     * @param query
     * @param listCallback
     */
    fun fetchAsync(query: String, listCallback: (List<String>) -> Unit) {
        val request = Request.Builder()
                .url(makeSuggestUrl(query))
                .build()
        httpClient.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) = Timber.e(e)

            @Throws(IOException::class)
            override fun onResponse(call: Call, response: Response) {
                if (response.body() == null) {
                    return
                }
                listCallback(SuggestionParser.parse(response.body()?.string() ?: ""))
            }
        })
    }

    /**
     * Make suggest Web API requesting URL.
     *
     * @param query Query
     * @return suggest Web API requesting URL
     */
    private fun makeSuggestUrl(query: String): String {
        return URL + "&hl=" + findHl(query) + "&q=" + Uri.encode(query)
    }

    /**
     * Find appropriate language.
     *
     * @param query
     * @return language (ex: "ja", "en")
     */
    private fun findHl(query: String): String {
        return if (Strings.containsMultiByte(query)) "ja" else Locale.getDefault().language
    }

    companion object {

        /**
         * Suggest Web API.
         */
        private const val URL = "https://www.google.com/complete/search?&output=toolbar"
    }
}
<commit_msg>refactor #433 Rewrite with elvis guard.<commit_after>package jp.toastkid.yobidashi.search.suggestion

import android.net.Uri
import jp.toastkid.yobidashi.libs.Strings
import jp.toastkid.yobidashi.libs.network.HttpClientFactory
import okhttp3.Call
import okhttp3.Callback
import okhttp3.Request
import okhttp3.Response
import timber.log.Timber
import java.io.IOException
import java.util.*

/**
 * Suggest Web API response fetcher.
 *
 * @author toastkidjp
 */
class SuggestionFetcher {

    /**
     * HTTP client.
     */
    private val httpClient = HttpClientFactory.withTimeout(3L)

    /**
     * Fetch Web API result asynchronously.
     *
     * @param query
     * @param listCallback
     */
    fun fetchAsync(query: String, listCallback: (List<String>) -> Unit) {
        val request = Request.Builder()
                .url(makeSuggestUrl(query))
                .build()
        httpClient.newCall(request).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) = Timber.e(e)

            @Throws(IOException::class)
            override fun onResponse(call: Call, response: Response) {
                val body = response.body()?.string() ?: return
                listCallback(SuggestionParser.parse(body))
            }
        })
    }

    /**
     * Make suggest Web API requesting URL.
     *
     * @param query Query
     * @return suggest Web API requesting URL
     */
    private fun makeSuggestUrl(query: String): String {
        return URL + "&hl=" + findHl(query) + "&q=" + Uri.encode(query)
    }

    /**
     * Find appropriate language.
     *
     * @param query
     * @return language (ex: "ja", "en")
     */
    private fun findHl(query: String): String {
        return if (Strings.containsMultiByte(query)) "ja" else Locale.getDefault().language
    }

    companion object {

        /**
         * Suggest Web API.
         */
        private const val URL = "https://www.google.com/complete/search?&output=toolbar"
    }
}

{'fraction_non_alphanumeric': 0.11601388200297472, 'fraction_numerical': 0.0032226078334159644, 'mean_word_length': 2.2885085574572126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '2772597', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1173, 'n_words': 275}