From d0dbdbeef8866fb5ce4cfb71a60652000738c49e Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Fri, 20 Dec 2024 02:47:55 +0100 Subject: [PATCH] Add 'fullTypePath' setting, give data types some love --- .../engine/base/EngineConfiguration.kt | 55 +++++++++++++--- .../staropensource/engine/base/type/Origin.kt | 6 +- .../engine/base/type/Tristate.kt | 62 +++++++++---------- .../engine/base/type/logging/Call.kt | 5 +- .../base/type/logging/ChannelSettings.kt | 3 + .../engine/base/type/logging/Feature.kt | 6 +- .../engine/base/type/logging/Level.kt | 6 +- .../engine/base/type/logging/OperationMode.kt | 6 +- .../engine/base/utility/Environment.kt | 22 ++++++- 9 files changed, 126 insertions(+), 45 deletions(-) diff --git a/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt b/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt index 97c81df..95d3ad8 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt @@ -50,14 +50,6 @@ class EngineConfiguration private constructor() { @Suppress("UNCHECKED_CAST") companion object { // -----> Core engine - /** - * Controls which [TimeZone] to use - * for date and time synchronization. - * - * @since v1-alpha10 - */ - var timezone: TimeZone = TimeZone.UTC - /** * Controls how the engine should shut down. * @@ -189,6 +181,53 @@ class EngineConfiguration private constructor() { var logFormatBuilder: KClass = SOSLSv2FormatBuilder::class as KClass + // -----> Miscellaneous + /** + * Controls which [TimeZone] to use + * for date and time synchronization. + * + * @since v1-alpha10 + */ + var timezone: TimeZone = TimeZone.UTC + + /** + * Controls whether the package + * of the data type class shall + * be prepended by the + * [toString] method of data types. + * + * Example: + * ```kotlin + * EngineConfiguration.fullTypePath = false + * println(Origin( + * packageName = "some.package", + * className = "SomeClass", + * methodName = "someMethod", + * lineNumber = 24u, + * )) + * + * println("----") + * + * EngineConfiguration.fullTypePath = true + * println(Origin( + * packageName = "some.package", + * className = "SomeClass", + * methodName = "someMethod", + * lineNumber = 24u, + * )) + * ``` + * Output: + * ```plain + * Origin(packageName = "some.package", className = "SomeClass", methodName = "someMethod", lineNumber = 24u) + * ---- + * de.staropensource.engine.base.type.Origin(packageName = "some.package", className = "SomeClass", methodName = "someMethod", lineNumber = 24u) + * ``` + * + * @since v1-alpha10 + */ + var fullTypePath: Boolean = false + + // -----> Management methods /** * Resets either the specified diff --git a/base/src/main/kotlin/de/staropensource/engine/base/type/Origin.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/Origin.kt index 65e4ef2..d105db2 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/type/Origin.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/Origin.kt @@ -19,6 +19,8 @@ package de.staropensource.engine.base.type +import de.staropensource.engine.base.EngineConfiguration + /** * Holds data about a method caller. * @@ -33,4 +35,6 @@ data class Origin( val className: String, val methodName: String, val lineNumber: UInt, -) +) { + override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type." else ""}Origin(packageName = \"${packageName}\", className = \"${className}\", methodName = \"${methodName}\", lineNumber = \"${lineNumber}\")" +} diff --git a/base/src/main/kotlin/de/staropensource/engine/base/type/Tristate.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/Tristate.kt index f7faa14..72e441f 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/type/Tristate.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/Tristate.kt @@ -19,6 +19,8 @@ package de.staropensource.engine.base.type +import de.staropensource.engine.base.EngineConfiguration + /** * Defines a data type which can have * three valid states: [UNSET], [TRUE] @@ -63,14 +65,13 @@ enum class Tristate { * @since v1-alpha10 */ @JvmStatic - fun toTristate(value: Boolean): Tristate { + fun of(value: Boolean): Tristate { return if (value) TRUE else FALSE } /** - * Converts the specified [Int] - * into a [Tristate]. + * Converts the specified [Int] into a [Tristate]. * * `0` represents [FALSE], * `1` represents [TRUE] and @@ -82,7 +83,7 @@ enum class Tristate { */ @JvmStatic @Throws(IndexOutOfBoundsException::class) - fun toTristate(value: Int): Tristate? { + fun of(value: Int): Tristate? { return when (value) { 0 -> FALSE 1 -> TRUE @@ -93,13 +94,12 @@ enum class Tristate { } /** - * Converts this [Tristate] into - * a [Boolean]. + * 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] + * @return [Boolean] representation or `null` if [UNSET] * @since v1-alpha10 */ fun toBoolean(): Boolean? { @@ -111,14 +111,13 @@ enum class Tristate { } /** - * Converts this [Tristate] into - * a [Byte]. + * 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] + * @return [Byte] representation or `null` if [UNSET] * @since v1-alpha10 */ fun toByte(): Byte { @@ -130,14 +129,13 @@ enum class Tristate { } /** - * Converts this [Tristate] into - * an [UByte]. + * 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] + * @return [UByte] representation or `null` if [UNSET] * @since v1-alpha10 */ fun toUByte(): UByte { @@ -149,14 +147,13 @@ enum class Tristate { } /** - * Converts this [Tristate] into - * a [Short]. + * 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] + * @return [Short] representation or `null` if [UNSET] * @since v1-alpha10 */ fun toShort(): Short { @@ -168,14 +165,13 @@ enum class Tristate { } /** - * Converts this [Tristate] into - * an [UShort]. + * 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] + * @return [UShort] representation or `null` if [UNSET] * @since v1-alpha10 */ fun toUShort(): UShort { @@ -187,14 +183,13 @@ enum class Tristate { } /** - * Converts this [Tristate] into - * an [Int]. + * 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] + * @return [Int] representation or `null` if [UNSET] * @since v1-alpha10 */ fun toInt(): Int { @@ -206,14 +201,13 @@ enum class Tristate { } /** - * Converts this [Tristate] into - * an [UInt]. + * 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] + * @return [UInt] representation or `null` if [UNSET] * @since v1-alpha10 */ fun toUInt(): UInt { @@ -225,14 +219,13 @@ enum class Tristate { } /** - * Converts this [Tristate] into - * a [Long]. + * 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] + * @return [Long] representation or `null` if [UNSET] * @since v1-alpha10 */ fun toLong(): Long { @@ -244,14 +237,13 @@ enum class Tristate { } /** - * Converts this [Tristate] into - * an [ULong]. + * 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] + * @return [ULong] representation or `null` if [UNSET] * @since v1-alpha10 */ fun toULong(): ULong { @@ -261,4 +253,12 @@ enum class Tristate { UNSET -> 2UL } } + + /** + * Converts this [Tristate] into a [String]. + * + * @return string representation + * @since v1-alpha10 + */ + override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type." else ""}Tristate.${name}" } diff --git a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt index f6f04c9..b1e1dfc 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt @@ -19,6 +19,7 @@ package de.staropensource.engine.base.type.logging +import de.staropensource.engine.base.EngineConfiguration import de.staropensource.engine.base.type.Origin /** @@ -35,4 +36,6 @@ data class Call( val level: Level, var message: String, val channel: String = "default", -) +) { + override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type.logging." else ""}Call(origin = ${origin}, level = Level.${level.name}, message = \"${message}\", channel = \"${channel}\")" +} diff --git a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt index 853dd80..38545fd 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt @@ -19,6 +19,7 @@ package de.staropensource.engine.base.type.logging +import de.staropensource.engine.base.EngineConfiguration import de.staropensource.engine.base.implementable.logging.Adapter import de.staropensource.engine.base.implementable.logging.Formatter import de.staropensource.engine.base.implementation.logging.NoOperationFormatter @@ -98,4 +99,6 @@ data class ChannelSettings( } } } + + override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type.logging." else ""}ChannelSettings(enable = ${enable}, sanitizeMessage = ${sanitizeMessage}, permitFormatting = ${permitFormatting}, applicationName = ${applicationName}, formatter = ${formatter}, adapters = ${adapters?.toList()}" } diff --git a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Feature.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Feature.kt index 1f76e6a..c0ada16 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Feature.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Feature.kt @@ -19,6 +19,8 @@ package de.staropensource.engine.base.type.logging +import de.staropensource.engine.base.EngineConfiguration + /** * Represents log formatting enabledFeatures. * @@ -80,5 +82,7 @@ enum class Feature { * * @since v1-alpha10 */ - LINE_NUMBER + LINE_NUMBER; + + override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type.logging." else ""}Feature.${name}" } diff --git a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Level.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Level.kt index 78d6d34..86c9c2d 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Level.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Level.kt @@ -19,6 +19,8 @@ package de.staropensource.engine.base.type.logging +import de.staropensource.engine.base.EngineConfiguration + /** * Represents log call priorities. * @@ -84,5 +86,7 @@ enum class Level { * * @since v1-alpha10 */ - CRASH + CRASH; + + override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type.logging." else ""}Level.${name}" } diff --git a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/OperationMode.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/OperationMode.kt index e3fb7a7..b573b99 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/OperationMode.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/OperationMode.kt @@ -19,6 +19,8 @@ package de.staropensource.engine.base.type.logging +import de.staropensource.engine.base.EngineConfiguration + /** * Represents how the logger functions. * @@ -38,5 +40,7 @@ enum class OperationMode { * * @since v1-alpha10 */ - NORMAL, + NORMAL; + + override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type.logging." else ""}OperationMode.${name}" } diff --git a/base/src/main/kotlin/de/staropensource/engine/base/utility/Environment.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/Environment.kt index 2328fd7..c55337a 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/utility/Environment.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/Environment.kt @@ -20,6 +20,7 @@ package de.staropensource.engine.base.utility import de.staropensource.engine.base.Engine.Companion.logger +import de.staropensource.engine.base.EngineConfiguration import de.staropensource.engine.base.utility.Environment.OperatingSystem.* import kotlinx.datetime.Instant import oshi.PlatformEnum @@ -430,7 +431,26 @@ class Environment private constructor() { * * @since v1-alpha10 */ - MACOS, + MACOS; + + override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.utility." else ""}Environment\$OperatingSystem.${name}" + + /** + * Returns the human-friendly name + * of this operating system. + * + * @return human-friendly name + * @since v1-alpha10 + */ + fun humanFriendly(): String = when (this) { + LINUX -> "Linux" + FREEBSD -> "FreeBSD" + NETBSD -> "NetBSD" + OPENBSD -> "OpenBSD" + ANDROID -> "Android" + WINDOWS -> "Windows" + MACOS -> "macOS" + } } /**