Add more Tristate.of methods

This commit is contained in:
JeremyStar™ 2024-12-20 19:36:18 +01:00
parent 35099737a4
commit e15ca5435c
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -70,6 +70,94 @@ enum class Tristate {
else FALSE
}
/**
* Converts the specified [Byte] into a [Tristate].
*
* `0` represents [FALSE],
* `1` represents [TRUE] and
* `2` represents [UNSET].
*
* @param value [Byte] to convert
* @return [Tristate] representation of the specified [Byte] or `null` if not in range `0` to `2`
* @since v1-alpha10
*/
@JvmStatic
@Throws(IndexOutOfBoundsException::class)
fun of(value: Byte): Tristate? {
return when (value) {
0.toByte() -> FALSE
1.toByte() -> TRUE
2.toByte() -> UNSET
else -> null
}
}
/**
* Converts the specified [UByte] into a [Tristate].
*
* `0` represents [FALSE],
* `1` represents [TRUE] and
* `2` represents [UNSET].
*
* @param value [UByte] to convert
* @return [Tristate] representation of the specified [UByte] or `null` if not in range `0` to `2`
* @since v1-alpha10
*/
@JvmStatic
@Throws(IndexOutOfBoundsException::class)
fun of(value: UByte): Tristate? {
return when (value) {
0u.toUByte() -> FALSE
1u.toUByte() -> TRUE
2u.toUByte() -> UNSET
else -> null
}
}
/**
* Converts the specified [Short] into a [Tristate].
*
* `0` represents [FALSE],
* `1` represents [TRUE] and
* `2` represents [UNSET].
*
* @param value [Short] to convert
* @return [Tristate] representation of the specified [Short] or `null` if not in range `0` to `2`
* @since v1-alpha10
*/
@JvmStatic
@Throws(IndexOutOfBoundsException::class)
fun of(value: Short): Tristate? {
return when (value) {
0.toShort() -> FALSE
1.toShort() -> TRUE
2.toShort() -> UNSET
else -> null
}
}
/**
* Converts the specified [UShort] into a [Tristate].
*
* `0` represents [FALSE],
* `1` represents [TRUE] and
* `2` represents [UNSET].
*
* @param value [UShort] to convert
* @return [Tristate] representation of the specified [UShort] or `null` if not in range `0` to `2`
* @since v1-alpha10
*/
@JvmStatic
@Throws(IndexOutOfBoundsException::class)
fun of(value: UShort): Tristate? {
return when (value) {
0u.toUShort() -> FALSE
1u.toUShort() -> TRUE
2u.toUShort() -> UNSET
else -> null
}
}
/**
* Converts the specified [Int] into a [Tristate].
*
@ -91,6 +179,72 @@ enum class Tristate {
else -> null
}
}
/**
* Converts the specified [UInt] into a [Tristate].
*
* `0` represents [FALSE],
* `1` represents [TRUE] and
* `2` represents [UNSET].
*
* @param value [UInt] to convert
* @return [Tristate] representation of the specified [UInt] or `null` if not in range `0` to `2`
* @since v1-alpha10
*/
@JvmStatic
@Throws(IndexOutOfBoundsException::class)
fun of(value: UInt): Tristate? {
return when (value) {
0u -> FALSE
1u -> TRUE
2u -> UNSET
else -> null
}
}
/**
* Converts the specified [Long] into a [Tristate].
*
* `0` represents [FALSE],
* `1` represents [TRUE] and
* `2` represents [UNSET].
*
* @param value [Long] to convert
* @return [Tristate] representation of the specified [Long] or `null` if not in range `0` to `2`
* @since v1-alpha10
*/
@JvmStatic
@Throws(IndexOutOfBoundsException::class)
fun of(value: Long): Tristate? {
return when (value) {
0L -> FALSE
1L -> TRUE
2L -> UNSET
else -> null
}
}
/**
* Converts the specified [ULong] into a [Tristate].
*
* `0` represents [FALSE],
* `1` represents [TRUE] and
* `2` represents [UNSET].
*
* @param value [ULong] to convert
* @return [Tristate] representation of the specified [ULong] or `null` if not in range `0` to `2`
* @since v1-alpha10
*/
@JvmStatic
@Throws(IndexOutOfBoundsException::class)
fun of(value: ULong): Tristate? {
return when (value) {
0UL -> FALSE
1UL -> TRUE
2UL -> UNSET
else -> null
}
}
}
/**