1 package net.pterodactylus.sone.utils
4 * Basic implementation of an [Option].
6 * @param <T> The type of the option
8 class DefaultOption<T> @JvmOverloads constructor(
9 private val defaultValue: T,
10 private val validator: ((T) -> Boolean)? = null
14 private var value: T? = null
16 override fun get() = value ?: defaultValue
18 override fun getReal(): T? = value
20 override fun validate(value: T?): Boolean =
21 value == null || validator?.invoke(value) ?: true
23 override fun set(value: T?) {
24 require(validate(value)) { "New Value ($value) could not be validated." }