com.mitteloupe.randomgenkt.fielddataprovider.RgbFieldDataProvider.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of randomgenkt Show documentation
Show all versions of randomgenkt Show documentation
Initialize instances of any class with generated data.
The newest version!
package com.mitteloupe.randomgenkt.fielddataprovider
import com.mitteloupe.randomgenkt.FieldDataProvider
import java.util.Random
class RgbFieldDataProvider(
private val random: Random,
private val provideAlpha: Boolean
) : FieldDataProvider() {
override fun invoke(instance: OUTPUT_TYPE?): String {
val red = random.nextInt(255)
val green = random.nextInt(255)
val blue = random.nextInt(255)
return when {
provideAlpha -> {
val alpha = random.nextInt(255)
String.format("#%02x%02x%02x%02x", alpha, red, green, blue)
}
else -> String.format("#%02x%02x%02x", red, green, blue)
}
}
}