<commit_before>/*
 * Copyright (c) 2019 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.yobidashi.menu

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.ListAdapter
import jp.toastkid.lib.preference.PreferenceApplier
import jp.toastkid.lib.view.list.CommonItemCallback
import jp.toastkid.yobidashi.R

/**
 * @author toastkidjp
 */
internal class MenuAdapter(
        private val inflater: LayoutInflater,
        private val preferenceApplier: PreferenceApplier,
        private val menuViewModel: MenuViewModel?
) : ListAdapter<Menu, MenuViewHolder>(
    CommonItemCallback.with({ a, b -> a.ordinal == b.ordinal }, { a, b -> a == b })
) {

    init {
        submitList(Menu.values().toList())
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MenuViewHolder =
            MenuViewHolder(
                    DataBindingUtil.inflate(inflater, LAYOUT_ID, parent, false)
            )

    override fun onBindViewHolder(holder: MenuViewHolder, position: Int) {
        val menu = getItem(position % currentList.size)
        holder.setColorPair(preferenceApplier.colorPair())
        holder.setText(menu.titleId)
        holder.setImage(menu.iconId)
        holder.setOnClick({ menuViewModel?.click(menu) })
        holder.setOnLongClick(
                View.OnLongClickListener {
                    menuViewModel?.longClick(menu)
                    true
                }
        )
    }

    override fun getItemCount(): Int = MAXIMUM

    companion object {

        /**
         * Layout ID.
         */
        @LayoutRes
        private const val LAYOUT_ID = R.layout.item_home_menu

        /**
         * Maximum length of menus.
         */
        private val MAXIMUM = Menu.values().size * 20

        /**
         * Medium position of menus.
         */
        private val MEDIUM = MAXIMUM / 2

        /**
         * Return medium position of menus.
         * @return MEDIUM
         */
        fun mediumPosition(): Int = MEDIUM
    }
}
<commit_msg>refactor #335 Remove redundant SAM-constructor.<commit_after>/*
 * Copyright (c) 2019 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.yobidashi.menu

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.ListAdapter
import jp.toastkid.lib.preference.PreferenceApplier
import jp.toastkid.lib.view.list.CommonItemCallback
import jp.toastkid.yobidashi.R

/**
 * @author toastkidjp
 */
internal class MenuAdapter(
        private val inflater: LayoutInflater,
        private val preferenceApplier: PreferenceApplier,
        private val menuViewModel: MenuViewModel?
) : ListAdapter<Menu, MenuViewHolder>(
    CommonItemCallback.with({ a, b -> a.ordinal == b.ordinal }, { a, b -> a == b })
) {

    init {
        submitList(Menu.values().toList())
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MenuViewHolder =
            MenuViewHolder(
                    DataBindingUtil.inflate(inflater, LAYOUT_ID, parent, false)
            )

    override fun onBindViewHolder(holder: MenuViewHolder, position: Int) {
        val menu = getItem(position % currentList.size)
        holder.setColorPair(preferenceApplier.colorPair())
        holder.setText(menu.titleId)
        holder.setImage(menu.iconId)
        holder.setOnClick({ menuViewModel?.click(menu) })
        holder.setOnLongClick(
            {
                menuViewModel?.longClick(menu)
                true
            }
        )
    }

    override fun getItemCount(): Int = MAXIMUM

    companion object {

        /**
         * Layout ID.
         */
        @LayoutRes
        private const val LAYOUT_ID = R.layout.item_home_menu

        /**
         * Maximum length of menus.
         */
        private val MAXIMUM = Menu.values().size * 20

        /**
         * Medium position of menus.
         */
        private val MEDIUM = MAXIMUM / 2

        /**
         * Return medium position of menus.
         * @return MEDIUM
         */
        fun mediumPosition(): Int = MEDIUM
    }
}

{'fraction_non_alphanumeric': 0.09235269536147096, 'fraction_numerical': 0.005223568742164647, 'mean_word_length': 2.3974449964513838, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '675584', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1314, 'n_words': 327}