package de.banananetwork.dsa.currencies import java.util.* import kotlin.collections.ArrayList class CurrencySet private constructor(private val currencies: Array) { fun transferToSet(baseValue: Int): Map { var modBaseValue = baseValue val values = EnumMap(Currency::class.java) for (currency in currencies) { val value = currency.transferTo(modBaseValue) values[currency] = value modBaseValue -= currency.transferFrom(value) } if (modBaseValue != 0) throw RuntimeException() // TODO Change to ValueNotRepresentableException return values } class Builder { private val currencies = ArrayList() fun add(currency: Currency): Builder { currencies.add(currency) return this } fun create(): CurrencySet { currencies.sortBy { it.multiplier } return CurrencySet(currencies.toTypedArray()) } } }