Add Tristate
All checks were successful
PRs & Pushes / build (push) Successful in 2m56s
PRs & Pushes / test (push) Successful in 2m54s
PRs & Pushes / build-apidoc (push) Successful in 2m21s

This commit is contained in:
JeremyStar™ 2024-12-20 00:35:43 +01:00
parent 611d7a93ff
commit 50e438a16b
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
6 changed files with 275 additions and 5 deletions

View file

@ -64,7 +64,7 @@ class Logger {
* @since v1-alpha10
*/
@JvmStatic
@Suppress("unused")
@Suppress("Unused")
val instance = Logger()
}

View file

@ -0,0 +1,265 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
* with an exception allowing classpath linking.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.base.type
/**
* Defines a data type which can have
* three valid states: [UNSET], [TRUE]
* and [FALSE].
*
* @since v1-alpha10
*/
@Suppress("Unused")
enum class Tristate {
/**
* Defines an unset state.
*
* @since v1-alpha10
*/
UNSET,
/**
* Defines a true state.
*
* @since v1-alpha10
*/
TRUE,
/**
* Defines a false state.
*
* @since v1-alpha10
*/
FALSE;
/**
* Companion object of [Tristate].
*
* @since v1-alpha10
*/
companion object {
/**
* Converts the specified [Boolean] into a [Tristate].
*
* @param value [Boolean] to convert
* @return [Tristate] representation of the specified [Boolean]
* @since v1-alpha10
*/
@JvmStatic
fun toTristate(value: Boolean): Tristate {
return if (value) TRUE
else FALSE
}
/**
* Converts the specified [Int]
* into a [Tristate].
*
* `0` represents [FALSE],
* `1` represents [TRUE] and
* `2` represents [UNSET].
*
* @param value [Int] to convert
* @return [Tristate] representation of the specified [Int] or `null` if not in range `0` to `2`
* @since v1-alpha10
*/
@JvmStatic
@Throws(IndexOutOfBoundsException::class)
fun toTristate(value: Int): Tristate? {
return when (value) {
0 -> FALSE
1 -> TRUE
2 -> UNSET
else -> null
}
}
}
/**
* Converts this [Tristate] into
* a [Boolean].
*
* If this [Tristate] is set to
* [UNSET], `null` will be returned.
*
* @return [Boolean] representation of this [Tristate] or `null` if [UNSET]
* @since v1-alpha10
*/
fun toBoolean(): Boolean? {
return when (this) {
TRUE -> true
FALSE -> false
UNSET -> null
}
}
/**
* Converts this [Tristate] into
* a [Byte].
*
* [FALSE] represents `0`,
* [TRUE] represents `1` and
* [UNSET] represents `2`.
*
* @return [Byte] representation of this [Tristate] or `null` if [UNSET]
* @since v1-alpha10
*/
fun toByte(): Byte {
return when (this) {
FALSE -> 0
TRUE -> 1
UNSET -> 2
}
}
/**
* Converts this [Tristate] into
* an [UByte].
*
* [FALSE] represents `0`,
* [TRUE] represents `1` and
* [UNSET] represents `2`.
*
* @return [UByte] representation of this [Tristate] or `null` if [UNSET]
* @since v1-alpha10
*/
fun toUByte(): UByte {
return when (this) {
FALSE -> 0u
TRUE -> 1u
UNSET -> 2u
}
}
/**
* Converts this [Tristate] into
* a [Short].
*
* [FALSE] represents `0`,
* [TRUE] represents `1` and
* [UNSET] represents `2`.
*
* @return [Short] representation of this [Tristate] or `null` if [UNSET]
* @since v1-alpha10
*/
fun toShort(): Short {
return when (this) {
FALSE -> 0
TRUE -> 1
UNSET -> 2
}
}
/**
* Converts this [Tristate] into
* an [UShort].
*
* [FALSE] represents `0`,
* [TRUE] represents `1` and
* [UNSET] represents `2`.
*
* @return [UShort] representation of this [Tristate] or `null` if [UNSET]
* @since v1-alpha10
*/
fun toUShort(): UShort {
return when (this) {
FALSE -> 0u
TRUE -> 1u
UNSET -> 2u
}
}
/**
* Converts this [Tristate] into
* an [Int].
*
* [FALSE] represents `0`,
* [TRUE] represents `1` and
* [UNSET] represents `2`.
*
* @return [Int] representation of this [Tristate] or `null` if [UNSET]
* @since v1-alpha10
*/
fun toInt(): Int {
return when (this) {
FALSE -> 0
TRUE -> 1
UNSET -> 2
}
}
/**
* Converts this [Tristate] into
* an [UInt].
*
* [FALSE] represents `0`,
* [TRUE] represents `1` and
* [UNSET] represents `2`.
*
* @return [UInt] representation of this [Tristate] or `null` if [UNSET]
* @since v1-alpha10
*/
fun toUInt(): UInt {
return when (this) {
FALSE -> 0u
TRUE -> 1u
UNSET -> 2u
}
}
/**
* Converts this [Tristate] into
* a [Long].
*
* [FALSE] represents `0`,
* [TRUE] represents `1` and
* [UNSET] represents `2`.
*
* @return [Long] representation of this [Tristate] or `null` if [UNSET]
* @since v1-alpha10
*/
fun toLong(): Long {
return when (this) {
FALSE -> 0L
TRUE -> 1L
UNSET -> 2L
}
}
/**
* Converts this [Tristate] into
* an [ULong].
*
* [FALSE] represents `0`,
* [TRUE] represents `1` and
* [UNSET] represents `2`.
*
* @return [ULong] representation of this [Tristate] or `null` if [UNSET]
* @since v1-alpha10
*/
fun toULong(): ULong {
return when (this) {
FALSE -> 0UL
TRUE -> 1UL
UNSET -> 2UL
}
}
}

View file

@ -33,7 +33,7 @@ import oshi.hardware.HardwareAbstractionLayer
*
* @since v1-alpha10
*/
@Suppress("unused")
@Suppress("Unused")
class Environment private constructor() {
/**
* Companion class of [Environment].

View file

@ -42,7 +42,7 @@ import java.nio.file.attribute.PosixFilePermissions
*
* @since v1-alpha10
*/
@Suppress("unused")
@Suppress("Unused")
class FileAccess {
/**
* Companion object of [FileAccess].

View file

@ -58,7 +58,7 @@ import java.util.*
// this: properties & getter methods, constructors,
// methods. This change was made for a better,
// less chaotic class source code layout.
@Suppress("unused")
@Suppress("Unused")
open class BuildInformation
@Throws(RuntimeException::class)
constructor(val loadPrefix: String, val loadLocation: FileAccess? = null) {

View file

@ -22,7 +22,12 @@
rootProject.name = "sos!engine"
// Subprojects
include("") // scan root
// -> Root
include("")
// -> Base
include("base")
// -> Testing
include("testapp")
include("testing")