X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Futil%2FVersion.java;h=00aeed89bed13ba29783fca6e8182395a2bcfa4a;hb=bbe38c55aaa999d025f534245f9207a88643f6e5;hp=ac42e13ae64fe24e2e23b297591b009d2f117326;hpb=a6cd86d5b65d3322c5f9acc8ecec207b3fe6d887;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/util/Version.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/util/Version.java index ac42e13a..00aeed89 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/util/Version.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/util/Version.java @@ -10,7 +10,7 @@ import com.google.gson.stream.JsonWriter; import net.mograsim.logic.model.util.Version.VersionJSONAdapter; @JsonAdapter(VersionJSONAdapter.class) -public final class Version +public final class Version implements Comparable { public final int major, minor, patch; @@ -88,6 +88,40 @@ public final class Version return is(major, minor) && this.patch == patch; } + /** + * Compares this {@link Version} with the specified version.
+ * As required by {@link Comparable#compareTo(Object)}, returns a negative integer, zero, or a positive integer as this version is less + * (earlier) than, equal to, or greater (later) than the specified version. + *

+ * If the versions are equal ({@link #major}, {@link #minor}, {@link #patch} are the same), returns 0.
+ * If they differ in {@link #patch}, but neither {@link #major} or {@link #minor} , returns +-1.
+ * If they differ in {@link #minor}, but not {@link #major}, returns +-2.
+ * If they differ in {@link #major}, returns +-3. + */ + @Override + public int compareTo(Version o) + { + if (major != o.major) + { + if (major > o.major) + return 3; + return -3; + } + if (minor != o.minor) + { + if (minor > o.minor) + return 2; + return -2; + } + if (patch != o.patch) + { + if (patch > o.patch) + return 1; + return -1; + } + return 0; + } + static class VersionJSONAdapter extends TypeAdapter { @Override