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 {
26 private final int major;
27 private final int minor;
28 private final int patch;
29 private final boolean isPre_1_20;
30 private final boolean hasPatch;
31 public HledgerVersion(int major, int minor) {
35 this.isPre_1_20 = false;
36 this.hasPatch = false;
38 public HledgerVersion(int major, int minor, int patch) {
42 this.isPre_1_20 = false;
45 public HledgerVersion(boolean pre_1_20) {
47 throw new IllegalArgumentException("pre_1_20 argument must be true");
48 this.major = this.minor = this.patch = 0;
49 this.isPre_1_20 = true;
50 this.hasPatch = false;
52 public HledgerVersion(HledgerVersion origin) {
53 this.major = origin.major;
54 this.minor = origin.minor;
55 this.isPre_1_20 = origin.isPre_1_20;
56 this.patch = origin.patch;
57 this.hasPatch = origin.hasPatch;
60 public boolean equals(@Nullable Object obj) {
63 if (!(obj instanceof HledgerVersion))
65 HledgerVersion that = (HledgerVersion) obj;
67 return (this.isPre_1_20 == that.isPre_1_20 && this.major == that.major &&
68 this.minor == that.minor && this.patch == that.patch &&
69 this.hasPatch == that.hasPatch);
71 public boolean isPre_1_20() {
74 public int getMajor() {
77 public int getMinor() {
80 public int getPatch() {
85 public String toString() {
87 return "(before 1.20)";
88 return hasPatch ? String.format(Locale.ROOT, "%d.%d.%d", major, minor, patch)
89 : String.format(Locale.ROOT, "%d.%d", major, minor);