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)
|
@Range(from = 0, to = 2)
|
||||||
int compare(@NotNull VersioningSystem version) throws IncompatibleVersioningSystemException;
|
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
|
} else
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
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
|
} else
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
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
|
} else
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
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;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the StarOpenSource versioning system (version 2), where an application
|
* Represents the StarOpenSource versioning
|
||||||
* or work is versioning by a {@code VERSION} vector, {@code TYPE} version type,
|
* system version two, where an application
|
||||||
* {@code TYPERELEASE} vector and optionally, a {@code FORK} vector and
|
* or work is versioning by the {@code RELEASE},
|
||||||
* {@code COMPANION} vector.
|
* {@code TYPE}, {@code TYPERELEASE} and
|
||||||
|
* optionally, the {@code FORK} and
|
||||||
|
* {@code COMPANION} vectors.
|
||||||
*
|
*
|
||||||
* @since v1-alpha1
|
* @since v1-alpha1
|
||||||
*/
|
*/
|
||||||
|
@ -44,16 +46,16 @@ import java.util.Locale;
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
@SuppressWarnings({ "JavadocDeclaration" })
|
||||||
public final class StarOpenSourceVersioningSystem implements VersioningSystem {
|
public final class StarOpenSourceVersioningSystem implements VersioningSystem {
|
||||||
/**
|
/**
|
||||||
* Contains the {@code VERSION} vector.
|
* Contains the {@code RELEASE} vector.
|
||||||
*
|
*
|
||||||
* @since v1-alpha1
|
* @since v1-alpha9
|
||||||
* -- GETTER --
|
* -- GETTER --
|
||||||
* Returns the {@code VERSION} vector.
|
* Returns the {@code RELEASE} vector.
|
||||||
*
|
*
|
||||||
* @return {@code VERSION} vector
|
* @return {@code RELEASE} vector
|
||||||
* @since v1-alpha1
|
* @since v1-alpha9
|
||||||
*/
|
*/
|
||||||
private final int version;
|
private final int release;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the {@code TYPE} vector.
|
* Contains the {@code TYPE} vector.
|
||||||
|
@ -121,7 +123,7 @@ public final class StarOpenSourceVersioningSystem implements VersioningSystem {
|
||||||
StringBuilder charSequence = new StringBuilder();
|
StringBuilder charSequence = new StringBuilder();
|
||||||
/*
|
/*
|
||||||
* 0 = 'v'
|
* 0 = 'v'
|
||||||
* 1 = version vector
|
* 1 = release vector
|
||||||
* 3 = type vector
|
* 3 = type vector
|
||||||
* 4 = typerelease vector
|
* 4 = typerelease vector
|
||||||
* 5 = companion vector
|
* 5 = companion vector
|
||||||
|
@ -223,7 +225,7 @@ public final class StarOpenSourceVersioningSystem implements VersioningSystem {
|
||||||
|
|
||||||
// Update variables
|
// Update variables
|
||||||
try {
|
try {
|
||||||
this.version = Integer.parseUnsignedInt(versionStringSplit.get(0));
|
this.release = Integer.parseUnsignedInt(versionStringSplit.get(0));
|
||||||
this.type = VersionType.valueOf(versionStringSplit.get(1));
|
this.type = VersionType.valueOf(versionStringSplit.get(1));
|
||||||
this.typerelease = Integer.parseUnsignedInt(versionStringSplit.get(2));
|
this.typerelease = Integer.parseUnsignedInt(versionStringSplit.get(2));
|
||||||
this.companion = companion;
|
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);
|
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");
|
throw new InvalidVersionStringException(this, versionString, "The version vector must start at 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,9 +243,9 @@ public final class StarOpenSourceVersioningSystem implements VersioningSystem {
|
||||||
@Override
|
@Override
|
||||||
public int compare(@NotNull VersioningSystem versionInterface) throws IncompatibleVersioningSystemException {
|
public int compare(@NotNull VersioningSystem versionInterface) throws IncompatibleVersioningSystemException {
|
||||||
if (versionInterface instanceof StarOpenSourceVersioningSystem versionCompare) {
|
if (versionInterface instanceof StarOpenSourceVersioningSystem versionCompare) {
|
||||||
if (versionCompare.getVersion() < this.version)
|
if (versionCompare.getRelease() < this.release)
|
||||||
return 0;
|
return 0;
|
||||||
if (versionCompare.getVersion() > this.version)
|
if (versionCompare.getRelease() > this.release)
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
if (type.compareTo(versionCompare.getType()) > 0)
|
if (type.compareTo(versionCompare.getType()) > 0)
|
||||||
|
@ -261,4 +263,10 @@ public final class StarOpenSourceVersioningSystem implements VersioningSystem {
|
||||||
} else
|
} else
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
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
|
} else
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
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
|
} else
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Override
|
||||||
|
public @NotNull String toString() {
|
||||||
|
return number1 + "." + number2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue