<commit_before>package ca.josephroque.bowlingcompanion.statistics

import android.os.Bundle
import ca.josephroque.bowlingcompanion.common.fragments.BaseFragment
import ca.josephroque.bowlingcompanion.statistics.provider.StatisticsProvider
import ca.josephroque.bowlingcompanion.statistics.provider.StatisticsProviderListFragment
import ca.josephroque.bowlingcompanion.statistics.unit.StatisticsUnitTabbedFragment

/**
 * Copyright (C) 2018 <NAME>
 *
 * Display the user's statistics.
 */
class BaseStatisticsFragment : BaseFragment() {

    companion object {
        /** Logging identifier. */
        @Suppress("unused")
        private const val TAG = "BaseStatisticsFragment"

        /** Argument identifier for the number of [StatisticsProvider]s that are present. */
        private const val ARG_STATISTICS_PROVIDER_COUNT = "${TAG}_count"

        /** Argument identifier for passing an array of [StatisticsProvider] type. */
        private const val ARG_STATISTICS_PROVIDER_TYPE = "${TAG}_type"

        /** Argument identifier for passing an array of [StatisticsProvider] to this fragment. */
        private const val ARG_STATISTICS_PROVIDER = "${TAG}_stats"

        /**
         * Creates a new instance.
         *
         * @return the new instance
         */
        fun newInstance(): BaseStatisticsFragment {
            return BaseStatisticsFragment()
        }

        /**
         * Build the bundle to provide as arguments for this fragment.
         *
         * @param statisticsProviders the statistics providers
         * @return [Bundle] to use for arguments
         */
        fun buildArguments(statisticsProviders: List<StatisticsProvider>): Bundle {
            return Bundle().apply {
                putInt(ARG_STATISTICS_PROVIDER_COUNT, statisticsProviders.size)
                putIntArray(ARG_STATISTICS_PROVIDER_TYPE, statisticsProviders.map { it.describeContents() }.toIntArray())
                statisticsProviders.forEachIndexed { index, it ->
                    putParcelable("${ARG_STATISTICS_PROVIDER}_$index", it)
                }
            }
        }
    }

    /** The stats being displayed. */
    private lateinit var statisticsProviders: List<StatisticsProvider>

    /** @Override */
    override fun onStart() {
        super.onStart()

        val providerCount = arguments?.getInt(ARG_STATISTICS_PROVIDER_COUNT) ?: 0
        statisticsProviders = if (providerCount > 0) {
            val types = arguments?.getIntArray(ARG_STATISTICS_PROVIDER_TYPE)
            arrayListOf<StatisticsProvider>().apply {
                types!!.forEachIndexed { index, it ->
                    val parcelable = StatisticsProvider.getParcelable(arguments, "${ARG_STATISTICS_PROVIDER}_$index", it)
                    add(parcelable!!)
                }
            }
        } else {
            emptyList()
        }

        // When there are no other fragments, push the relevant fragment onto the stack
        val isOnlyFragment = (fragmentNavigation?.stackSize ?: 1) == 1
        if (isOnlyFragment) {
            val newFragment: BaseFragment = when {
                statisticsProviders.isEmpty() -> TODO("not implemented")
                statisticsProviders.size == 1 -> StatisticsUnitTabbedFragment.newInstance(statisticsProviders[0])
                else -> StatisticsProviderListFragment.newInstance(statisticsProviders)
            }
<commit_msg>Remove options menu from previous fragment in statistics<commit_after>package ca.josephroque.bowlingcompanion.statistics

import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import ca.josephroque.bowlingcompanion.common.fragments.BaseFragment
import ca.josephroque.bowlingcompanion.statistics.provider.StatisticsProvider
import ca.josephroque.bowlingcompanion.statistics.provider.StatisticsProviderListFragment
import ca.josephroque.bowlingcompanion.statistics.unit.StatisticsUnitTabbedFragment

/**
 * Copyright (C) 2018 <NAME>
 *
 * Display the user's statistics.
 */
class BaseStatisticsFragment : BaseFragment() {

    companion object {
        /** Logging identifier. */
        @Suppress("unused")
        private const val TAG = "BaseStatisticsFragment"

        /** Argument identifier for the number of [StatisticsProvider]s that are present. */
        private const val ARG_STATISTICS_PROVIDER_COUNT = "${TAG}_count"

        /** Argument identifier for passing an array of [StatisticsProvider] type. */
        private const val ARG_STATISTICS_PROVIDER_TYPE = "${TAG}_type"

        /** Argument identifier for passing an array of [StatisticsProvider] to this fragment. */
        private const val ARG_STATISTICS_PROVIDER = "${TAG}_stats"

        /**
         * Creates a new instance.
         *
         * @return the new instance
         */
        fun newInstance(): BaseStatisticsFragment {
            return BaseStatisticsFragment()
        }

        /**
         * Build the bundle to provide as arguments for this fragment.
         *
         * @param statisticsProviders the statistics providers
         * @return [Bundle] to use for arguments
         */
        fun buildArguments(statisticsProviders: List<StatisticsProvider>): Bundle {
            return Bundle().apply {
                putInt(ARG_STATISTICS_PROVIDER_COUNT, statisticsProviders.size)
                putIntArray(ARG_STATISTICS_PROVIDER_TYPE, statisticsProviders.map { it.describeContents() }.toIntArray())
                statisticsProviders.forEachIndexed { index, it ->
                    putParcelable("${ARG_STATISTICS_PROVIDER}_$index", it)
                }
            }
        }
    }

    /** The stats being displayed. */
    private lateinit var statisticsProviders: List<StatisticsProvider>

    /** @Override */
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setHasOptionsMenu(true)
    }

    /** @Override */
    override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
        menu?.clear()
        super.onCreateOptionsMenu(menu, inflater)
    }

    /** @Override */
    override fun onStart() {
        super.onStart()

        val providerCount = arguments?.getInt(ARG_STATISTICS_PROVIDER_COUNT) ?: 0
        statisticsProviders = if (providerCount > 0) {
            val types = arguments?.getIntArray(ARG_STATISTICS_PROVIDER_TYPE)
            arrayListOf<StatisticsProvider>().apply {
                types!!.forEachIndexed { index, it ->
                    val parcelable = StatisticsProvider.getParcelable(arguments, "${ARG_STATISTICS_PROVIDER}_$index", it)
                    add(parcelable!!)
                }
            }
        } else {
            emptyList()
        }

        // When there are no other fragments, push the relevant fragment onto the stack
        val isOnlyFragment = (fragmentNavigation?.stackSize ?: 1) == 1
        if (isOnlyFragment) {
            val newFragment: BaseFragment = when {
                statisticsProviders.isEmpty() -> TODO("not implemented")
                statisticsProviders.size == 1 -> StatisticsUnitTabbedFragment.newInstance(statisticsProviders[0])
                else -> StatisticsProviderListFragment.newInstance(statisticsProviders)
            }

{'fraction_non_alphanumeric': 0.08769994484280198, 'fraction_numerical': 0.0027578599007170436, 'mean_word_length': 2.5658800393313665, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '6893372', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1820, 'n_words': 424}