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

import android.content.Context
import io.reactivex.Completable
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import jp.toastkid.yobidashi.libs.db.DatabaseFinder
import timber.log.Timber

/**
 * @author toastkidjp
 */
class SearchHistoryInsertion private constructor(
        private val context: Context,
        private val category: String,
        private val query: String
) {

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

    fun insert(): Disposable {
        if (category.isEmpty() || query.isEmpty()) {
            return EMPTY
        }
        return insert(SearchHistory.make(category, query))
    }

    private fun insert(searchHistory: SearchHistory) =
            Completable.fromAction { repository.insert(searchHistory) }
                    .subscribeOn(Schedulers.io())
                    .subscribe(
                            {},
                            Timber::e
                    )

    companion object {

        private val EMPTY = object : Disposable {
            override fun dispose() {

            }

            override fun isDisposed(): Boolean {
                return false
            }
        }

        fun make(
                context: Context,
                category: String,
                query: String
        ): SearchHistoryInsertion {
            return SearchHistoryInsertion(context, category, query)
        }
    }
}<commit_msg>refactor #440 Delete unused constants instead of Disposables.empty().<commit_after>package jp.toastkid.yobidashi.search.history

import android.content.Context
import io.reactivex.Completable
import io.reactivex.disposables.Disposable
import io.reactivex.disposables.Disposables
import io.reactivex.schedulers.Schedulers
import jp.toastkid.yobidashi.libs.db.DatabaseFinder
import timber.log.Timber

/**
 * @author toastkidjp
 */
class SearchHistoryInsertion private constructor(
        private val context: Context,
        private val category: String,
        private val query: String
) {

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

    fun insert(): Disposable {
        if (category.isEmpty() || query.isEmpty()) {
            return Disposables.empty()
        }
        return insert(SearchHistory.make(category, query))
    }

    private fun insert(searchHistory: SearchHistory) =
            Completable.fromAction { repository.insert(searchHistory) }
                    .subscribeOn(Schedulers.io())
                    .subscribe(
                            {},
                            Timber::e
                    )

    companion object {

        fun make(
                context: Context,
                category: String,
                query: String
        ): SearchHistoryInsertion {
            return SearchHistoryInsertion(context, category, query)
        }
    }
}
{'fraction_non_alphanumeric': 0.0825016633399867, 'fraction_numerical': 0.000998003992015968, 'mean_word_length': 1.9920398009950249, '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': '6544310', 'n_tokens_mistral': 786, 'n_tokens_neox': 737, 'n_words': 165}