diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2019-02-03 21:15:22 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2019-02-03 21:15:22 +0800 |
| commit | 074a627663e0150e23d47a87486afb852dd2cfdd (patch) | |
| tree | 0b030485400ed6f03c41b791018ef0c00229b80f /src/main/java/me/shedaniel/rei/update/Version.java | |
| parent | b7abefc2eca79112a2bcc4c1be0629be2f17fb91 (diff) | |
| download | RoughlyEnoughItems-2.2.0.16.tar.gz RoughlyEnoughItems-2.2.0.16.tar.bz2 RoughlyEnoughItems-2.2.0.16.zip | |
Version Checker + Mirror REI + Fix Bugsv2.2.0.16
Diffstat (limited to 'src/main/java/me/shedaniel/rei/update/Version.java')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/update/Version.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/rei/update/Version.java b/src/main/java/me/shedaniel/rei/update/Version.java new file mode 100644 index 000000000..32d34eb3f --- /dev/null +++ b/src/main/java/me/shedaniel/rei/update/Version.java @@ -0,0 +1,49 @@ +package me.shedaniel.rei.update; + +public class Version implements Comparable<Version> { + + private String version; + + public Version(String version) { + if (version == null) + throw new IllegalArgumentException("Version can not be null"); + if (!version.matches("[0-9]+(\\.[0-9]+)*")) + throw new IllegalArgumentException("Invalid version format"); + this.version = version; + } + + @Override + public final String toString() { + return this.version; + } + + @Override + public int compareTo(Version other) { + if (other == null) + return 1; + String[] thisParts = this.toString().split("\\."); + String[] thatParts = other.toString().split("\\."); + int length = Math.max(thisParts.length, thatParts.length); + for(int i = 0; i < length; i++) { + int thisPart = i < thisParts.length ? Integer.parseInt(thisParts[i]) : 0; + int thatPart = i < thatParts.length ? Integer.parseInt(thatParts[i]) : 0; + if (thisPart < thatPart) + return -1; + if (thisPart > thatPart) + return 1; + } + return 0; + } + + @Override + public boolean equals(Object that) { + if (this == that) + return true; + if (that == null) + return false; + if (this.getClass() != that.getClass()) + return false; + return this.compareTo((Version) that) == 0; + } + +}
\ No newline at end of file |
