From 1e978e314687109fefa4a0966d772bb0facac338 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 8 Dec 2024 00:10:15 +0100 Subject: [PATCH] Add toString() method to VersioningSystem --- .../base/implementable/VersioningSystem.java | 9 +++++ .../FourNumberVersioningSystem.java | 6 +++ .../versioning/OneNumberVersioningSystem.java | 6 +++ .../versioning/SemanticVersioningSystem.java | 6 +++ .../StarOpenSourceVersioningSystem.java | 38 +++++++++++-------- .../ThreeNumberVersioningSystem.java | 6 +++ .../versioning/TwoNumberVersioningSystem.java | 6 +++ 7 files changed, 62 insertions(+), 15 deletions(-) diff --git a/base/src/main/java/de/staropensource/engine/base/implementable/VersioningSystem.java b/base/src/main/java/de/staropensource/engine/base/implementable/VersioningSystem.java index 841457a..c7808b2 100644 --- a/base/src/main/java/de/staropensource/engine/base/implementable/VersioningSystem.java +++ b/base/src/main/java/de/staropensource/engine/base/implementable/VersioningSystem.java @@ -47,4 +47,13 @@ public interface VersioningSystem { */ @Range(from = 0, to = 2) int compare(@NotNull VersioningSystem version) throws IncompatibleVersioningSystemException; + + /** + * Returns the version string. + * + * @return version string + * @since v1-alpha9 + */ + @Override + @NotNull String toString(); } diff --git a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/FourNumberVersioningSystem.java b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/FourNumberVersioningSystem.java index 55088d6..59cb8c8 100644 --- a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/FourNumberVersioningSystem.java +++ b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/FourNumberVersioningSystem.java @@ -151,4 +151,10 @@ public final class FourNumberVersioningSystem implements VersioningSystem { } else throw new IncompatibleVersioningSystemException(this, versionInterface); } + + /** {@inheritDoc} */ + @Override + public @NotNull String toString() { + return number1 + "." + number2 + "." + number3 + "." + number4; + } } diff --git a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/OneNumberVersioningSystem.java b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/OneNumberVersioningSystem.java index 68bfbce..5972c9b 100644 --- a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/OneNumberVersioningSystem.java +++ b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/OneNumberVersioningSystem.java @@ -82,4 +82,10 @@ public final class OneNumberVersioningSystem implements VersioningSystem { } else throw new IncompatibleVersioningSystemException(this, versionInterface); } + + /** {@inheritDoc} */ + @Override + public @NotNull String toString() { + return String.valueOf(number); + } } diff --git a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/SemanticVersioningSystem.java b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/SemanticVersioningSystem.java index 8f867fc..30d56ee 100644 --- a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/SemanticVersioningSystem.java +++ b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/SemanticVersioningSystem.java @@ -220,4 +220,10 @@ public final class SemanticVersioningSystem implements VersioningSystem { } else throw new IncompatibleVersioningSystemException(this, versionInterface); } + + /** {@inheritDoc} */ + @Override + public @NotNull String toString() { + return major + "." + minor + "." + patch + (prerelease == null ? "" : "-" + prerelease) + (build == 0 ? "" : "+" + build); + } } diff --git a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/StarOpenSourceVersioningSystem.java b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/StarOpenSourceVersioningSystem.java index 71cc948..eeb17b1 100644 --- a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/StarOpenSourceVersioningSystem.java +++ b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/StarOpenSourceVersioningSystem.java @@ -33,10 +33,12 @@ import java.util.List; import java.util.Locale; /** - * Represents the StarOpenSource versioning system (version 2), where an application - * or work is versioning by a {@code VERSION} vector, {@code TYPE} version type, - * {@code TYPERELEASE} vector and optionally, a {@code FORK} vector and - * {@code COMPANION} vector. + * Represents the StarOpenSource versioning + * system version two, where an application + * or work is versioning by the {@code RELEASE}, + * {@code TYPE}, {@code TYPERELEASE} and + * optionally, the {@code FORK} and + * {@code COMPANION} vectors. * * @since v1-alpha1 */ @@ -44,16 +46,16 @@ import java.util.Locale; @SuppressWarnings({ "JavadocDeclaration" }) public final class StarOpenSourceVersioningSystem implements VersioningSystem { /** - * Contains the {@code VERSION} vector. + * Contains the {@code RELEASE} vector. * - * @since v1-alpha1 + * @since v1-alpha9 * -- GETTER -- - * Returns the {@code VERSION} vector. + * Returns the {@code RELEASE} vector. * - * @return {@code VERSION} vector - * @since v1-alpha1 + * @return {@code RELEASE} vector + * @since v1-alpha9 */ - private final int version; + private final int release; /** * Contains the {@code TYPE} vector. @@ -121,7 +123,7 @@ public final class StarOpenSourceVersioningSystem implements VersioningSystem { StringBuilder charSequence = new StringBuilder(); /* * 0 = 'v' - * 1 = version vector + * 1 = release vector * 3 = type vector * 4 = typerelease vector * 5 = companion vector @@ -223,7 +225,7 @@ public final class StarOpenSourceVersioningSystem implements VersioningSystem { // Update variables try { - this.version = Integer.parseUnsignedInt(versionStringSplit.get(0)); + this.release = Integer.parseUnsignedInt(versionStringSplit.get(0)); this.type = VersionType.valueOf(versionStringSplit.get(1)); this.typerelease = Integer.parseUnsignedInt(versionStringSplit.get(2)); this.companion = companion; @@ -232,7 +234,7 @@ public final class StarOpenSourceVersioningSystem implements VersioningSystem { throw new InvalidVersionStringException(this, versionString, "Failed converting one of the vectors to an integer", exception); } - if (this.version == 0) + if (this.release == 0) throw new InvalidVersionStringException(this, versionString, "The version vector must start at 1"); } @@ -241,9 +243,9 @@ public final class StarOpenSourceVersioningSystem implements VersioningSystem { @Override public int compare(@NotNull VersioningSystem versionInterface) throws IncompatibleVersioningSystemException { if (versionInterface instanceof StarOpenSourceVersioningSystem versionCompare) { - if (versionCompare.getVersion() < this.version) + if (versionCompare.getRelease() < this.release) return 0; - if (versionCompare.getVersion() > this.version) + if (versionCompare.getRelease() > this.release) return 2; if (type.compareTo(versionCompare.getType()) > 0) @@ -261,4 +263,10 @@ public final class StarOpenSourceVersioningSystem implements VersioningSystem { } else throw new IncompatibleVersioningSystemException(this, versionInterface); } + + /** {@inheritDoc} */ + @Override + public @NotNull String toString() { + return "v" + release + "-" + type.name().toLowerCase(Locale.ROOT) + typerelease + (fork == null ? "" : "-" + fork) + (companion == null ? "" : "+" + companion); + } } diff --git a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/ThreeNumberVersioningSystem.java b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/ThreeNumberVersioningSystem.java index 84bbbe3..e92c4c6 100644 --- a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/ThreeNumberVersioningSystem.java +++ b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/ThreeNumberVersioningSystem.java @@ -133,4 +133,10 @@ public final class ThreeNumberVersioningSystem implements VersioningSystem { } else throw new IncompatibleVersioningSystemException(this, versionInterface); } + + /** {@inheritDoc} */ + @Override + public @NotNull String toString() { + return number1 + "." + number2 + "." + number3; + } } diff --git a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/TwoNumberVersioningSystem.java b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/TwoNumberVersioningSystem.java index 6922ec2..1ab7502 100644 --- a/base/src/main/java/de/staropensource/engine/base/implementation/versioning/TwoNumberVersioningSystem.java +++ b/base/src/main/java/de/staropensource/engine/base/implementation/versioning/TwoNumberVersioningSystem.java @@ -115,4 +115,10 @@ public final class TwoNumberVersioningSystem implements VersioningSystem { } else throw new IncompatibleVersioningSystemException(this, versionInterface); } + + /** {@inheritDoc} */ + @Override + public @NotNull String toString() { + return number1 + "." + number2; + } }