Add VersionType class for SOSVS

This commit is contained in:
JeremyStar™ 2024-12-19 02:46:51 +01:00
parent 9b264ca6cc
commit 70e81a7a2c
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 175 additions and 0 deletions

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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
}
}
}
}

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
/**
* Data types used for representing
* versioning information.
*
* @since v1-alpha10
*/
package de.staropensource.engine.base.type.versioning;