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 java.util.Locale;
25 public class HledgerVersion {
29 private boolean isPre_1_20;
30 private boolean hasPatch;
31 public HledgerVersion(int major, int minor) {
34 this.isPre_1_20 = false;
35 this.hasPatch = false;
37 public HledgerVersion(int major, int minor, int patch) {
41 this.isPre_1_20 = false;
44 public HledgerVersion(boolean pre_1_20) {
46 throw new IllegalArgumentException("pre_1_20 argument must be true");
47 this.major = this.minor = 0;
48 this.isPre_1_20 = true;
49 this.hasPatch = false;
51 public HledgerVersion(HledgerVersion origin) {
52 this.major = origin.major;
53 this.minor = origin.minor;
54 this.isPre_1_20 = origin.isPre_1_20;
55 this.patch = origin.patch;
56 this.hasPatch = origin.hasPatch;
59 public boolean equals(@Nullable Object obj) {
62 if (!(obj instanceof HledgerVersion))
64 HledgerVersion that = (HledgerVersion) obj;
66 return (this.isPre_1_20 == that.isPre_1_20 && this.major == that.major &&
67 this.minor == that.minor && this.patch == that.patch &&
68 this.hasPatch == that.hasPatch);
70 public boolean isPre_1_20() {
73 public int getMajor() {
76 public int getMinor() {
79 public int getPatch() {
84 public String toString() {
86 return "(before 1.20)";
87 return hasPatch ? String.format(Locale.ROOT, "%d.%d.%d", major, minor, patch)
88 : String.format(Locale.ROOT, "%d.%d", major, minor);