Andrea Giuliano
10/10/2020, 5:46 PMclass ControlledMap(type: Type, index: Int) {
private val table = mapOf(type to index)
fun get(type: Type): Int =
table.getOrElse(type) { throw IllegalArgumentException("Trying to get a non existing content from ControlledMap") }
operator fun plus(other: ControlledMap): ControlledMap {
if (table.keys.any { other.table.containsKey(it) }) {
throw IllegalArgumentException("Cannot merge ControlledMaps with clashing keys")
}
// want to return a new ControlledMap where table is the union of the 2 tables (this.table + other.table)
}
enum class Type {
A,
B,
C,
D
}
}
Milan Hruban
10/10/2020, 5:58 PMAndrea Giuliano
10/10/2020, 6:38 PM