2 * Copyright © 2020 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.model;
20 import androidx.annotation.NonNull;
21 import androidx.annotation.Nullable;
23 import net.ktnx.mobileledger.async.SendTransactionTask;
25 import java.util.Locale;
27 public class HledgerVersion {
28 private final int major;
29 private final int minor;
30 private final int patch;
31 private final boolean isPre_1_20_1;
32 private final boolean hasPatch;
33 public HledgerVersion(int major, int minor) {
37 this.isPre_1_20_1 = false;
38 this.hasPatch = false;
40 public HledgerVersion(int major, int minor, int patch) {
44 this.isPre_1_20_1 = false;
47 public HledgerVersion(boolean pre_1_20_1) {
49 throw new IllegalArgumentException("pre_1_20_1 argument must be true");
50 this.major = this.minor = this.patch = 0;
51 this.isPre_1_20_1 = true;
52 this.hasPatch = false;
54 public HledgerVersion(HledgerVersion origin) {
55 this.major = origin.major;
56 this.minor = origin.minor;
57 this.isPre_1_20_1 = origin.isPre_1_20_1;
58 this.patch = origin.patch;
59 this.hasPatch = origin.hasPatch;
62 public boolean equals(@Nullable Object obj) {
65 if (!(obj instanceof HledgerVersion))
67 HledgerVersion that = (HledgerVersion) obj;
69 return (this.isPre_1_20_1 == that.isPre_1_20_1 && this.major == that.major &&
70 this.minor == that.minor && this.patch == that.patch &&
71 this.hasPatch == that.hasPatch);
73 public boolean isPre_1_20_1() {
76 public int getMajor() {
79 public int getMinor() {
82 public int getPatch() {
87 public String toString() {
89 return "(before 1.20)";
90 return hasPatch ? String.format(Locale.ROOT, "%d.%d.%d", major, minor, patch)
91 : String.format(Locale.ROOT, "%d.%d", major, minor);
93 public boolean atLeast(int major, int minor) {
94 return ((this.major == major) && (this.minor >= minor)) || (this.major > major);
96 @org.jetbrains.annotations.Nullable
97 public SendTransactionTask.API getSuitableApiVersion() {
101 return SendTransactionTask.API.v1_19_1;