mirror of
https://github.com/GTNewHorizons/GTNHLib.git
synced 2026-11-28 07:35:51 +00:00
Support major.minor.patch version format in PackVersion (#371)
This commit is contained in:
1 parent
34b2c2b6e7
commit
951f0350d4
1 file changed
+13
-6
@@ -4,10 +4,12 @@ final class PackVersion implements Comparable<PackVersion> {
|
||||
|
||||
final int major;
|
||||
final int minor;
|
||||
final int patch;
|
||||
|
||||
private PackVersion(int major, int minor) {
|
||||
private PackVersion(int major, int minor, int patch) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
}
|
||||
|
||||
static PackVersion parse(String value) {
|
||||
@@ -15,15 +17,16 @@ final class PackVersion implements Comparable<PackVersion> {
|
||||
throw new IllegalArgumentException("Version is null");
|
||||
}
|
||||
String[] parts = value.trim().split("\\.");
|
||||
if (parts.length != 2) {
|
||||
throw new IllegalArgumentException("Version must be major.minor: " + value);
|
||||
if (parts.length < 2 || parts.length > 3) {
|
||||
throw new IllegalArgumentException("Version must be major.minor or major.minor.patch: " + value);
|
||||
}
|
||||
int major = Integer.parseInt(parts[0]);
|
||||
int minor = Integer.parseInt(parts[1]);
|
||||
if (major < 0 || minor < 0) {
|
||||
int patch = parts.length == 3 ? Integer.parseInt(parts[2]) : 0;
|
||||
if (major < 0 || minor < 0 || patch < 0) {
|
||||
throw new IllegalArgumentException("Version must be non-negative: " + value);
|
||||
}
|
||||
return new PackVersion(major, minor);
|
||||
return new PackVersion(major, minor, patch);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,6 +35,10 @@ final class PackVersion implements Comparable<PackVersion> {
|
||||
if (majorCompare != 0) {
|
||||
return majorCompare;
|
||||
}
|
||||
return Integer.compare(this.minor, other.minor);
|
||||
int minorCompare = Integer.compare(this.minor, other.minor);
|
||||
if (minorCompare != 0) {
|
||||
return minorCompare;
|
||||
}
|
||||
return Integer.compare(this.patch, other.patch);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user