X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FHledgerVersion.java;h=235f8c729bdfde5e73a8d89c8bd23936ccd02a9f;hb=bb789332571609eeb1bef6e39b7ad359227d1045;hp=f3cbba213e4218e0e8dfdb68d4f2528d92144a89;hpb=667ce42731c95a98926657fea359b56209f9348e;p=mobile-ledger-staging.git diff --git a/app/src/main/java/net/ktnx/mobileledger/model/HledgerVersion.java b/app/src/main/java/net/ktnx/mobileledger/model/HledgerVersion.java index f3cbba21..235f8c72 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/HledgerVersion.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/HledgerVersion.java @@ -20,38 +20,41 @@ package net.ktnx.mobileledger.model; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import net.ktnx.mobileledger.json.API; + import java.util.Locale; public class HledgerVersion { - private int major; - private int minor; - private int patch; - private boolean isPre_1_20; - private boolean hasPatch; + private final int major; + private final int minor; + private final int patch; + private final boolean isPre_1_20_1; + private final boolean hasPatch; public HledgerVersion(int major, int minor) { this.major = major; this.minor = minor; - this.isPre_1_20 = false; + this.patch = 0; + this.isPre_1_20_1 = false; this.hasPatch = false; } public HledgerVersion(int major, int minor, int patch) { this.major = major; this.minor = minor; this.patch = patch; - this.isPre_1_20 = false; + this.isPre_1_20_1 = false; this.hasPatch = true; } - public HledgerVersion(boolean pre_1_20) { - if (!pre_1_20) - throw new IllegalArgumentException("pre_1_20 argument must be true"); - this.major = this.minor = 0; - this.isPre_1_20 = true; + public HledgerVersion(boolean pre_1_20_1) { + if (!pre_1_20_1) + throw new IllegalArgumentException("pre_1_20_1 argument must be true"); + this.major = this.minor = this.patch = 0; + this.isPre_1_20_1 = true; this.hasPatch = false; } public HledgerVersion(HledgerVersion origin) { this.major = origin.major; this.minor = origin.minor; - this.isPre_1_20 = origin.isPre_1_20; + this.isPre_1_20_1 = origin.isPre_1_20_1; this.patch = origin.patch; this.hasPatch = origin.hasPatch; } @@ -63,12 +66,12 @@ public class HledgerVersion { return false; HledgerVersion that = (HledgerVersion) obj; - return (this.isPre_1_20 == that.isPre_1_20 && this.major == that.major && + return (this.isPre_1_20_1 == that.isPre_1_20_1 && this.major == that.major && this.minor == that.minor && this.patch == that.patch && this.hasPatch == that.hasPatch); } - public boolean isPre_1_20() { - return isPre_1_20; + public boolean isPre_1_20_1() { + return isPre_1_20_1; } public int getMajor() { return major; @@ -82,9 +85,19 @@ public class HledgerVersion { @NonNull @Override public String toString() { - if (isPre_1_20) + if (isPre_1_20_1) return "(before 1.20)"; return hasPatch ? String.format(Locale.ROOT, "%d.%d.%d", major, minor, patch) : String.format(Locale.ROOT, "%d.%d", major, minor); } + public boolean atLeast(int major, int minor) { + return ((this.major == major) && (this.minor >= minor)) || (this.major > major); + } + @org.jetbrains.annotations.Nullable + public API getSuitableApiVersion() { + if (isPre_1_20_1) + return null; + + return API.v1_19_1; + } }