Skip to content

Commit

Permalink
refactor: use requireNonNull from Kotlin std instead of NullUtils (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
DataM0del authored Dec 22, 2024
1 parent 4d3a3c7 commit 20784f6
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/main/kotlin/info/opensigma/setting/owner/SettingOwner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,48 @@ package info.opensigma.setting.owner
import info.opensigma.setting.Setting
import info.opensigma.system.ElementRepository
import info.opensigma.system.INameable
import net.jezevcik.argon.utils.objects.NullUtils

@Suppress("UNCHECKED_CAST")
class SettingOwner<T>(owner: INameable) : ElementRepository<Setting<T>>("${owner.name}-settings",
Setting::class.java as Class<Setting<T>>, toScan = arrayOf(owner)) {

fun getBooleanValue(name: String): Boolean {
return NullUtils.requireNotNull(getByName(name)?.value, "Setting $name does not exist!") as Boolean
return requireNotNull(getByName(name)?.value, { "Setting $name does not exist!" }) as Boolean
}

fun getIntValue(name: String): Int {
return NullUtils.requireNotNull(getByName(name)?.value, "Setting $name does not exist!") as Int
return requireNotNull(getByName(name)?.value, { "Setting $name does not exist!" }) as Int
}

fun getFloatValue(name: String): Float {
return NullUtils.requireNotNull(getByName(name)?.value, "Setting $name does not exist!") as Float
return requireNotNull(getByName(name)?.value, { "Setting $name does not exist!" }) as Float
}

fun getDoubleValue(name: String): Double {
return NullUtils.requireNotNull(getByName(name)?.value, "Setting $name does not exist!") as Double
return requireNotNull(getByName(name)?.value, { "Setting $name does not exist!" }) as Double
}

fun getLongValue(name: String): Long {
return NullUtils.requireNotNull(getByName(name)?.value, "Setting $name does not exist!") as Long
return requireNotNull(getByName(name)?.value, { "Setting $name does not exist!" }) as Long
}

fun getShortValue(name: String): Short {
return NullUtils.requireNotNull(getByName(name)?.value, "Setting $name does not exist!") as Short
return requireNotNull(getByName(name)?.value, { "Setting $name does not exist!" }) as Short
}

fun getByteValue(name: String): Byte {
return NullUtils.requireNotNull(getByName(name)?.value, "Setting $name does not exist!") as Byte
return requireNotNull(getByName(name)?.value, { "Setting $name does not exist!" }) as Byte
}

fun getCharValue(name: String): Char {
return NullUtils.requireNotNull(getByName(name)?.value, "Setting $name does not exist!") as Char
return requireNotNull(getByName(name)?.value, { "Setting $name does not exist!" }) as Char
}

fun getStringValue(name: String): String {
return NullUtils.requireNotNull(getByName(name)?.value, "Setting $name does not exist!") as String
return requireNotNull(getByName(name)?.value, { "Setting $name does not exist!" }) as String
}

fun getObjectValue(name: String): Any {
return NullUtils.requireNotNull(getByName(name)?.value as Any, "Setting $name does not exist!")
return requireNotNull(getByName(name)?.value as Any, { "Setting $name does not exist!" })
}
}
}

0 comments on commit 20784f6

Please sign in to comment.