All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.elderscrollslegends.CardGrouping.kt Maven / Gradle / Ivy

There is a newer version: 1.1.7
Show newest version
package io.elderscrollslegends

open class CardGrouping(val cards: List) {
    // A map of count to list of cards with that count in the deck, e.g. {1: [Adoring Fan, Aela the Huntress], 2: [Aldmeri Patriot]}
    private val countToCardListMap = cards
        .groupBy { it.id }                                     // Map>
        .map { it.value.size to it.value.first() }             // List>
        .groupBy { it.first }                                  // Map>>
        .map { it.key to it.value.map { p -> p.second }.sortedBy { card -> card.name } }      // List>
        .toMap()                                               // Map>

    // A map of cardId to DeckCard
    private val deckCardMap = cards
        .groupBy { it.id }
        .map { it.value.first().id to CardCount(card = it.value.first(), count = it.value.size) }
        .toMap()

    fun of(count: Int) = countToCardListMap.getOrDefault(count, emptyList())

    fun byId(cardId: String): CardCount {
        return deckCardMap.getOrDefault(cardId, CardCount())
    }
}

data class CardCount(
    val card: Card? = null,
    val count: Int = 0
)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy