@@ -19,6 +19,8 @@ import com.demonwav.mcdev.util.SemanticVersion.Companion.VersionPart.ReleasePart
1919 * to the version ranking with decreasing priority from left to right.
2020 */
2121class SemanticVersion (val parts : List <VersionPart >) : Comparable<SemanticVersion> {
22+ val versionString = parts.map { it.versionString }.joinToString(" ." );
23+
2224 override fun compareTo (other : SemanticVersion ): Int {
2325 // Zipping limits the compared parts to the shorter version, then we perform a component-wise comparison
2426 // Short-circuits if any component of this version is smaller/older
@@ -39,8 +41,6 @@ class SemanticVersion(val parts: List<VersionPart>) : Comparable<SemanticVersion
3941
4042 override fun hashCode () = parts.hashCode()
4143
42- override fun toString () = parts.map { it.toString() }.joinToString(" ." )
43-
4444 companion object {
4545 /* *
4646 * Parses a version string into a comparable representation.
@@ -71,24 +71,26 @@ class SemanticVersion(val parts: List<VersionPart>) : Comparable<SemanticVersion
7171 }
7272
7373 sealed class VersionPart : Comparable <VersionPart > {
74+ abstract val versionString: String
75+
7476 data class ReleasePart (val version : Int ) : VersionPart() {
77+ override val versionString = version.toString()
78+
7579 override fun compareTo (other : VersionPart ) =
7680 when (other) {
7781 is PreReleasePart -> if (version != other.version) version - other.version else 1
7882 is ReleasePart -> version - other.version
7983 }
80-
81- override fun toString () = version.toString()
8284 }
8385
8486 data class PreReleasePart (val version : Int , val pre : Int ) : VersionPart() {
87+ override val versionString = " ${version} _pre$pre "
88+
8589 override fun compareTo (other : VersionPart ) =
8690 when (other) {
8791 is PreReleasePart -> if (version != other.version) version - other.version else pre - other.pre
8892 is ReleasePart -> if (version != other.version) version - other.version else - 1
8993 }
90-
91- override fun toString () = " ${version} _pre$pre "
9294 }
9395 }
9496 }
0 commit comments