Add n1 versioning system
This commit is contained in:
parent
ff7c559a39
commit
165855c122
1 changed files with 87 additions and 0 deletions
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue