From 165855c12250d508e4eff94c84dbf68350373770 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Thu, 11 Jul 2024 14:31:42 +0200 Subject: [PATCH] Add n1 versioning system --- .../versioning/OneNumberVersioningSystem.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 base/src/main/java/de/staropensource/sosengine/base/data/versioning/OneNumberVersioningSystem.java diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/versioning/OneNumberVersioningSystem.java b/base/src/main/java/de/staropensource/sosengine/base/data/versioning/OneNumberVersioningSystem.java new file mode 100644 index 00000000..aa6567ea --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/versioning/OneNumberVersioningSystem.java @@ -0,0 +1,87 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * Licensed under the GNU Affero General Public License v3 + * + * 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.sosengine.base.data.versioning; + +import de.staropensource.sosengine.base.exceptions.IncompatibleVersioningSystemException; +import de.staropensource.sosengine.base.exceptions.InvalidVersionStringException; +import de.staropensource.sosengine.base.types.versioning.VersioningSystem; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Range; + +/** + * Represents a two-numbered versioning system, where an application or work is versioning by two arbitrary numbers. + * + * @since 1-alpha1 + */ +@SuppressWarnings({ "unused", "JavadocDeclaration", "JavadocBlankLines" }) +@Getter +public final class OneNumberVersioningSystem implements VersioningSystem { + /** + * Contains the number vector. + * + * @since 1-alpha1 + * + * -- GETTER -- + * Returns the number vector. + * + * @return number vector + * @since 1-alpha1 + */ + private final int number; + + /** {@inheritDoc} */ + @NotNull + @Override + public String getName() { + return "n1"; + } + + /** + * Parses a one number-based version string. + * + * @param versionString version string to parse + * @throws InvalidVersionStringException if the version string is invalid + */ + public OneNumberVersioningSystem(@NotNull String versionString) throws InvalidVersionStringException { + // Convert to integers + try { + this.number = Integer.parseUnsignedInt(versionString); + } catch (NumberFormatException exception) { + throw new InvalidVersionStringException(this, versionString, "Failed converting the version string into an integer", exception); + } + } + + /** {@inheritDoc} */ + @Range(from = 0, to = 2) + @Override + public int compare(@NotNull VersioningSystem versionInterface) throws IncompatibleVersioningSystemException { + if (versionInterface instanceof OneNumberVersioningSystem version) { + if (version.getNumber() < number) + return 0; + if (version.getNumber() > number) + return 2; + + return 1; + + } else + throw new IncompatibleVersioningSystemException(this, versionInterface); + } +}