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

com.skillw.pouvoir.api.plugin.map.MultiMap.kt Maven / Gradle / Ivy

There is a newer version: 1.6.7-beta-6
Show newest version
package com.skillw.pouvoir.api.plugin.map

/**
 * Multi exec map
 *
 * @constructor Create empty Multi exec map
 */
open class MultiMap : BaseMap>() {
    fun add(key: K, value: V): Boolean = (computeIfAbsent(key) { ArrayList() } as MutableList).add(value)
    fun remove(key: K, value: V): Boolean = (get(key) as MutableList?)?.remove(value) ?: false
    operator fun plusAssign(map: MultiMap) {
        addAll(map)
    }

    operator fun plusAssign(pair: Pair) {
        add(pair.first, pair.second)
    }

    fun addAll(map: MultiMap) {
        map.keys.forEach { key ->
            map[key]?.forEach { value ->
                add(key, value)
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy