X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FHledgerVersion.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FHledgerVersion.java;h=f3cbba213e4218e0e8dfdb68d4f2528d92144a89;hp=0000000000000000000000000000000000000000;hb=667ce42731c95a98926657fea359b56209f9348e;hpb=9b2ed5acac2771812a115f83273691b55185c4fd diff --git a/app/src/main/java/net/ktnx/mobileledger/model/HledgerVersion.java b/app/src/main/java/net/ktnx/mobileledger/model/HledgerVersion.java new file mode 100644 index 00000000..f3cbba21 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/model/HledgerVersion.java @@ -0,0 +1,90 @@ +/* + * Copyright © 2020 Damyan Ivanov. + * This file is part of MoLe. + * MoLe is free software: you can distribute it and/or modify it + * under the term of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your opinion), any later version. + * + * MoLe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License terms for details. + * + * You should have received a copy of the GNU General Public License + * along with MoLe. If not, see . + */ + +package net.ktnx.mobileledger.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.Locale; + +public class HledgerVersion { + private int major; + private int minor; + private int patch; + private boolean isPre_1_20; + private boolean hasPatch; + public HledgerVersion(int major, int minor) { + this.major = major; + this.minor = minor; + this.isPre_1_20 = 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.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; + this.hasPatch = false; + } + public HledgerVersion(HledgerVersion origin) { + this.major = origin.major; + this.minor = origin.minor; + this.isPre_1_20 = origin.isPre_1_20; + this.patch = origin.patch; + this.hasPatch = origin.hasPatch; + } + @Override + public boolean equals(@Nullable Object obj) { + if (obj == null) + return false; + if (!(obj instanceof HledgerVersion)) + return false; + HledgerVersion that = (HledgerVersion) obj; + + return (this.isPre_1_20 == that.isPre_1_20 && 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 int getMajor() { + return major; + } + public int getMinor() { + return minor; + } + public int getPatch() { + return patch; + } + @NonNull + @Override + public String toString() { + if (isPre_1_20) + return "(before 1.20)"; + return hasPatch ? String.format(Locale.ROOT, "%d.%d.%d", major, minor, patch) + : String.format(Locale.ROOT, "%d.%d", major, minor); + } +}