com.skillw.pouvoir.api.plugin.map.MultiMap.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Pouvoir Show documentation
Show all versions of Pouvoir Show documentation
Bukkit Script Engine Plugin.
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