package com.gh.gamecenter.download

import com.gh.gamecenter.common.base.BaseSimpleDao

/**
 * 用来记录光环下载过什么包名和游戏ID间合集的一个简单类
 */
class DownloadedGameIdAndPackageNameDao : BaseSimpleDao() {

    /**
     * 删掉包名关联的条目
     */
    fun removeOldPackageItem(packageName: String) {
        val oldItemSet = hashSetOf<String>()
        getAll()?.iterator()?.let {
            while (it.hasNext()) {
                val item = it.next()
                if (item.endsWith(packageName)) {
                    oldItemSet.add(item)
                }
            }
        }

        for (item in oldItemSet) {
            delete(item)
        }
    }

    override fun getSPKey() = "downloaded_game_id_and_packagename"

    override fun getMaxSize(): Int = 1000

}