forked from StarOpenSource/Engine
Add toString() method to VersioningSystem
This commit is contained in:
parent
499d704695
commit
1e978e3146
7 changed files with 62 additions and 15 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue