pawel.barszcz
05/26/2017, 3:00 PMColor class:
data class Color private constructor(
val red: Int,
val green: Int,
val blue: Int
) {
companion object {
fun of(red: Int, green: Int, blue: Int): Color {
if (isInvalidPigment(red)) throw IllegalArgumentException("Red pigment is invalid.")
if (isInvalidPigment(green)) throw IllegalArgumentException("Green pigment is invalid.")
if (isInvalidPigment(blue)) throw IllegalArgumentException("Blue pigment is invalid.")
return Color(red, green, blue)
}
private fun isInvalidPigment(pigment: Int) = pigment < 0 || pigment > 255
}
}