]> git.ktnx.net Git - mobile-ledger-staging.git/blob - app/src/main/java/net/ktnx/mobileledger/model/HledgerVersion.java
UI and machinery for detecting hledger-web version
[mobile-ledger-staging.git] / app / src / main / java / net / ktnx / mobileledger / model / HledgerVersion.java
1 /*
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.ktnx.mobileledger.model;
19
20 import androidx.annotation.NonNull;
21 import androidx.annotation.Nullable;
22
23 import java.util.Locale;
24
25 public class HledgerVersion {
26     private int major;
27     private int minor;
28     private int patch;
29     private boolean isPre_1_20;
30     private boolean hasPatch;
31     public HledgerVersion(int major, int minor) {
32         this.major = major;
33         this.minor = minor;
34         this.isPre_1_20 = false;
35         this.hasPatch = false;
36     }
37     public HledgerVersion(int major, int minor, int patch) {
38         this.major = major;
39         this.minor = minor;
40         this.patch = patch;
41         this.isPre_1_20 = false;
42         this.hasPatch = true;
43     }
44     public HledgerVersion(boolean pre_1_20) {
45         if (!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;
50     }
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;
57     }
58     @Override
59     public boolean equals(@Nullable Object obj) {
60         if (obj == null)
61             return false;
62         if (!(obj instanceof HledgerVersion))
63             return false;
64         HledgerVersion that = (HledgerVersion) obj;
65
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);
69     }
70     public boolean isPre_1_20() {
71         return isPre_1_20;
72     }
73     public int getMajor() {
74         return major;
75     }
76     public int getMinor() {
77         return minor;
78     }
79     public int getPatch() {
80         return patch;
81     }
82     @NonNull
83     @Override
84     public String toString() {
85         if (isPre_1_20)
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);
89     }
90 }