]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java
more pronounced day/month delimiters in the transaction list
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / TemplateHeader.java
1 /*
2  * Copyright © 2022 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.db;
19
20 import androidx.annotation.NonNull;
21 import androidx.annotation.Nullable;
22 import androidx.room.ColumnInfo;
23 import androidx.room.Entity;
24 import androidx.room.Index;
25 import androidx.room.PrimaryKey;
26
27 import net.ktnx.mobileledger.utils.Misc;
28
29 import org.jetbrains.annotations.NotNull;
30
31 import java.util.UUID;
32
33 @Entity(tableName = "templates",
34         indices = {@Index(name = "templates_uuid_idx", unique = true, value = "uuid")})
35 public class TemplateHeader extends TemplateBase {
36     @PrimaryKey(autoGenerate = true)
37     private long id;
38     @ColumnInfo(name = "name")
39     @NonNull
40     private String name;
41     @NonNull
42     @ColumnInfo
43     private String uuid;
44     @NonNull
45     @ColumnInfo(name = "regular_expression")
46     private String regularExpression;
47     @ColumnInfo(name = "test_text")
48     private String testText;
49     @ColumnInfo(name = "transaction_description")
50     private String transactionDescription;
51     @ColumnInfo(name = "transaction_description_match_group")
52     private Integer transactionDescriptionMatchGroup;
53     @ColumnInfo(name = "transaction_comment")
54     private String transactionComment;
55     @ColumnInfo(name = "transaction_comment_match_group")
56     private Integer transactionCommentMatchGroup;
57     @ColumnInfo(name = "date_year")
58     private Integer dateYear;
59     @ColumnInfo(name = "date_year_match_group")
60     private Integer dateYearMatchGroup;
61     @ColumnInfo(name = "date_month")
62     private Integer dateMonth;
63     @ColumnInfo(name = "date_month_match_group")
64     private Integer dateMonthMatchGroup;
65     @ColumnInfo(name = "date_day")
66     private Integer dateDay;
67     @ColumnInfo(name = "date_day_match_group")
68     private Integer dateDayMatchGroup;
69     @ColumnInfo(name = "is_fallback")
70     private boolean isFallback;
71     public TemplateHeader(@NotNull Long id, @NonNull String name,
72                           @NonNull String regularExpression) {
73         this.id = id;
74         this.name = name;
75         this.regularExpression = regularExpression;
76         this.uuid = UUID.randomUUID()
77                         .toString();
78     }
79     public TemplateHeader(TemplateHeader origin) {
80         id = origin.id;
81         name = origin.name;
82         uuid = origin.uuid;
83         regularExpression = origin.regularExpression;
84         testText = origin.testText;
85         transactionDescription = origin.transactionDescription;
86         transactionDescriptionMatchGroup = origin.transactionDescriptionMatchGroup;
87         transactionComment = origin.transactionComment;
88         transactionCommentMatchGroup = origin.transactionCommentMatchGroup;
89         dateYear = origin.dateYear;
90         dateYearMatchGroup = origin.dateYearMatchGroup;
91         dateMonth = origin.dateMonth;
92         dateMonthMatchGroup = origin.dateMonthMatchGroup;
93         dateDay = origin.dateDay;
94         dateDayMatchGroup = origin.dateDayMatchGroup;
95         isFallback = origin.isFallback;
96     }
97     @NonNull
98     public String getUuid() {
99         return uuid;
100     }
101     public void setUuid(@NonNull String uuid) {
102         this.uuid = uuid;
103     }
104     public boolean isFallback() {
105         return isFallback;
106     }
107     public void setFallback(boolean fallback) {
108         isFallback = fallback;
109     }
110     public String getTestText() {
111         return testText;
112     }
113     public void setTestText(String testText) {
114         this.testText = testText;
115     }
116     public Integer getTransactionDescriptionMatchGroup() {
117         return transactionDescriptionMatchGroup;
118     }
119     public void setTransactionDescriptionMatchGroup(Integer transactionDescriptionMatchGroup) {
120         this.transactionDescriptionMatchGroup = transactionDescriptionMatchGroup;
121     }
122     public Integer getTransactionCommentMatchGroup() {
123         return transactionCommentMatchGroup;
124     }
125     public void setTransactionCommentMatchGroup(Integer transactionCommentMatchGroup) {
126         this.transactionCommentMatchGroup = transactionCommentMatchGroup;
127     }
128     public Integer getDateYear() {
129         return dateYear;
130     }
131     public void setDateYear(Integer dateYear) {
132         this.dateYear = dateYear;
133     }
134     public Integer getDateMonth() {
135         return dateMonth;
136     }
137     public void setDateMonth(Integer dateMonth) {
138         this.dateMonth = dateMonth;
139     }
140     public Integer getDateDay() {
141         return dateDay;
142     }
143     public void setDateDay(Integer dateDay) {
144         this.dateDay = dateDay;
145     }
146     public long getId() {
147         return id;
148     }
149     public void setId(long id) {
150         this.id = id;
151     }
152     @NonNull
153     public String getName() {
154         return name;
155     }
156     public void setName(@NonNull String name) {
157         this.name = name;
158     }
159     @NonNull
160     public String getRegularExpression() {
161         return regularExpression;
162     }
163     public void setRegularExpression(@NonNull String regularExpression) {
164         this.regularExpression = regularExpression;
165     }
166     public String getTransactionDescription() {
167         return transactionDescription;
168     }
169     public void setTransactionDescription(String transactionDescription) {
170         this.transactionDescription = transactionDescription;
171     }
172     public String getTransactionComment() {
173         return transactionComment;
174     }
175     public void setTransactionComment(String transactionComment) {
176         this.transactionComment = transactionComment;
177     }
178     public Integer getDateYearMatchGroup() {
179         return dateYearMatchGroup;
180     }
181     public void setDateYearMatchGroup(Integer dateYearMatchGroup) {
182         this.dateYearMatchGroup = dateYearMatchGroup;
183     }
184     public Integer getDateMonthMatchGroup() {
185         return dateMonthMatchGroup;
186     }
187     public void setDateMonthMatchGroup(Integer dateMonthMatchGroup) {
188         this.dateMonthMatchGroup = dateMonthMatchGroup;
189     }
190     public Integer getDateDayMatchGroup() {
191         return dateDayMatchGroup;
192     }
193     public void setDateDayMatchGroup(Integer dateDayMatchGroup) {
194         this.dateDayMatchGroup = dateDayMatchGroup;
195     }
196     @Override
197     public boolean equals(@Nullable Object obj) {
198         if (obj == null)
199             return false;
200         if (!(obj instanceof TemplateHeader))
201             return false;
202
203         TemplateHeader o = (TemplateHeader) obj;
204
205         return Misc.equalLongs(id, o.id) && Misc.equalStrings(name, o.name) &&
206                Misc.equalStrings(regularExpression, o.regularExpression) &&
207                Misc.equalStrings(transactionDescription, o.transactionDescription) &&
208                Misc.equalStrings(transactionComment, o.transactionComment) &&
209                Misc.equalIntegers(transactionDescriptionMatchGroup,
210                        o.transactionDescriptionMatchGroup) &&
211                Misc.equalIntegers(transactionCommentMatchGroup, o.transactionCommentMatchGroup) &&
212                Misc.equalIntegers(dateDay, o.dateDay) &&
213                Misc.equalIntegers(dateDayMatchGroup, o.dateDayMatchGroup) &&
214                Misc.equalIntegers(dateMonth, o.dateMonth) &&
215                Misc.equalIntegers(dateMonthMatchGroup, o.dateMonthMatchGroup) &&
216                Misc.equalIntegers(dateYear, o.dateYear) &&
217                Misc.equalIntegers(dateYearMatchGroup, o.dateYearMatchGroup);
218     }
219     public TemplateHeader createDuplicate() {
220         TemplateHeader dup = new TemplateHeader(this);
221         dup.id = 0;
222         dup.uuid = UUID.randomUUID()
223                        .toString();
224
225         return dup;
226     }
227 }