<commit_before>/*
 * Copyright (c) 2021 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */

package jp.toastkid.article_viewer.article.detail.usecase

import jp.toastkid.lib.view.TextViewHighlighter
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch

class ContentTextSearchUseCase(
    private val textViewHighlighter: TextViewHighlighter,
    private val inputChannel: Channel<String> = Channel(),
    private val mainDispatcher: CoroutineDispatcher = Dispatchers.Main,
    private val backgroundDispatcher: CoroutineDispatcher = Dispatchers.Default
) {

    operator fun invoke(keyword: String?) {
        if (keyword.isNullOrBlank()) {
            return
        }

        CoroutineScope(backgroundDispatcher).launch {
            inputChannel.send(keyword)
        }
    }

    fun startObserve() {
        CoroutineScope(backgroundDispatcher).launch {
            inputChannel
                .receiveAsFlow()
                .distinctUntilChanged()<commit_msg>refactor #580 Add @VisibleForTesting annotation.<commit_after>/*
 * Copyright (c) 2021 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */

package jp.toastkid.article_viewer.article.detail.usecase

import androidx.annotation.VisibleForTesting
import jp.toastkid.lib.view.TextViewHighlighter
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch

class ContentTextSearchUseCase(
    private val textViewHighlighter: TextViewHighlighter,
    @VisibleForTesting private val inputChannel: Channel<String> = Channel(),
    @VisibleForTesting private val mainDispatcher: CoroutineDispatcher = Dispatchers.Main,
    @VisibleForTesting private val backgroundDispatcher: CoroutineDispatcher = Dispatchers.Default
) {

    operator fun invoke(keyword: String?) {
        if (keyword.isNullOrBlank()) {
            return
        }

        CoroutineScope(backgroundDispatcher).launch {
            inputChannel.send(keyword)
        }
    }

    fun startObserve() {
        CoroutineScope(backgroundDispatcher).launch {
            inputChannel
                .receiveAsFlow()
                .distinctUntilChanged()
{'fraction_non_alphanumeric': 0.07346189164370982, 'fraction_numerical': 0.0058157330884603614, 'mean_word_length': 3.974124809741248, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '4828993', 'n_tokens_mistral': 967, 'n_tokens_neox': 921, 'n_words': 204}