From 70e81a7a2cb1b912a6f7a95a6ac1f545c86ef44e Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Thu, 19 Dec 2024 02:46:51 +0100 Subject: [PATCH] Add VersionType class for SOSVS --- .../base/type/versioning/VersionType.kt | 148 ++++++++++++++++++ .../base/type/versioning/package-info.kt | 27 ++++ 2 files changed, 175 insertions(+) create mode 100644 base/src/main/kotlin/de/staropensource/engine/base/type/versioning/VersionType.kt create mode 100644 base/src/main/kotlin/de/staropensource/engine/base/type/versioning/package-info.kt diff --git a/base/src/main/kotlin/de/staropensource/engine/base/type/versioning/VersionType.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/versioning/VersionType.kt new file mode 100644 index 0000000..8b58ca3 --- /dev/null +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/versioning/VersionType.kt @@ -0,0 +1,148 @@ +/* + * 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 . + */ + +package de.staropensource.engine.base.type.versioning + +/** + * Contains all version types of all + * [SOSVS](z.staropensource.de/spec-versioning) + * specifications. + * + * @since v1-alpha10 + */ +class VersionType { + /** + * Represents the version types + * found in the [second iteration](z.staropensource.de/spec-versioning-v2) + * of the [SOSVS specification](z.staropensource.de/spec-versioning). + * + * @since v1-alpha10 + */ + enum class V2 { + /** + * Identifies the work as experimental. + * + * The work may have many unresolved + * issues and may change significantly + * during further development. + * + * Usage is not recommended. + * + * @since v1-alpha10 + */ + ALPHA, + + /** + * Identifies the work as unstable. + * + * The work may have a few unresolved + * issues and may change from time to + * time during further development. + * + * Usage is not recommended. + * + * @since v1-alpha10 + */ + BETA, + + /** + * Identifies the work as potentially + * stable. The work may have a few + * smaller issues but it's shape is + * final. No new features may be + * added anymore unless required. + * + * Usage only recommended for testers + * and early birds. + * + * @since v1-alpha10 + */ + RELEASECANDIDATE, + + /** + * Identifies the work as tested and + * stable. + * + * The work is finished and can be + * used without any problems. + * + * @since v1-alpha10 + */ + RELEASE; + + /** + * Companion object of [V2]. + * + * @since v1-alpha10 + */ + companion object { + /** + * Converts the specified string into + * the correct version type. + * + * @return matching version type or `null` + * @since v1-alpha10 + */ + fun of(string: String): V2? { + return when (string) { + "alpha" -> ALPHA + "beta" -> BETA + "releasecandidate" -> RELEASECANDIDATE + "release" -> RELEASE + else -> null + } + } + } + + /** + * Returns this version type + * as it's proper string + * representation. + * + * @return string representation + * @since v1-alpha10 + */ + override fun toString(): String { + return when (this) { + ALPHA -> "alpha" + BETA -> "beta" + RELEASECANDIDATE -> "releasecandidate" + RELEASE -> "release" + } + } + + /** + * Returns this version type + * as it's proper byte + * representation. + * + * @return byte representation + * @since v1-alpha10 + */ + fun toUByte(): UByte { + return when (this) { + ALPHA -> 0u + BETA -> 1u + RELEASECANDIDATE -> 2u + RELEASE -> 3u + } + } + } +} diff --git a/base/src/main/kotlin/de/staropensource/engine/base/type/versioning/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/versioning/package-info.kt new file mode 100644 index 0000000..47e2524 --- /dev/null +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/versioning/package-info.kt @@ -0,0 +1,27 @@ +/* + * 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 . + */ + +/** + * Data types used for representing + * versioning information. + * + * @since v1-alpha10 + */ +package de.staropensource.engine.base.type.versioning;