<commit_before>package jp.toastkid.yobidashi.browser.history

import android.content.Context
import jp.toastkid.yobidashi.libs.db.DatabaseFinder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch

/**
 * @author toastkidjp
 */
class ViewHistoryInsertion private constructor(
        context: Context,
        private val title: String,
        private val url: String,
        private val faviconPath: String
) {

    private val repository = DatabaseFinder().invoke(context).viewHistoryRepository()

    operator fun invoke(): Job =
            if (title.isEmpty() || url.isEmpty()) Job()
            else insert(makeItem(title, url, faviconPath))

    private fun insert(searchHistory: ViewHistory): Job =
        CoroutineScope(Dispatchers.IO).launch {
            repository.add(searchHistory)
        }

    private fun makeItem(title: String, url: String, faviconPath: String): ViewHistory =
        ViewHistory().also {
            it.title = title
            it.url = url
            it.favicon = faviconPath
            it.lastViewed = System.currentTimeMillis()
        }

    companion object {

        fun make(
                context: Context,
                title: String,
                url: String,
                faviconPath: String
        ) = ViewHistoryInsertion(context, title, url, faviconPath)
    }
}<commit_msg>refactor #605 Add factory function's comment.<commit_after>package jp.toastkid.yobidashi.browser.history

import android.content.Context
import jp.toastkid.yobidashi.libs.db.DatabaseFinder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch

/**
 * @author toastkidjp
 */
class ViewHistoryInsertion private constructor(
        context: Context,
        private val title: String,
        private val url: String,
        private val faviconPath: String
) {

    private val repository = DatabaseFinder().invoke(context).viewHistoryRepository()

    operator fun invoke(): Job =
            if (title.isEmpty() || url.isEmpty()) Job()
            else insert(makeItem(title, url, faviconPath))

    private fun insert(searchHistory: ViewHistory): Job =
        CoroutineScope(Dispatchers.IO).launch {
            repository.add(searchHistory)
        }

    private fun makeItem(title: String, url: String, faviconPath: String): ViewHistory =
        ViewHistory().also {
            it.title = title
            it.url = url
            it.favicon = faviconPath
            it.lastViewed = System.currentTimeMillis()
        }

    companion object {

        /**
         * Make object with content strings.
         *
         * @param context For obtaining repository
         * @param title title string
         * @param url URL string
         * @param faviconPath Path to favicon
         */
        fun make(
                context: Context,
                title: String,
                url: String,
                faviconPath: String
        ) = ViewHistoryInsertion(context, title, url, faviconPath)
    }
}
{'fraction_non_alphanumeric': 0.08680445151033386, 'fraction_numerical': 0.0009538950715421304, 'mean_word_length': 2.382795698924731, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5328552', 'n_tokens_mistral': 871, 'n_tokens_neox': 846, 'n_words': 210}