2 * Copyright © 2021 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.db;
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;
27 import net.ktnx.mobileledger.utils.Misc;
29 import org.jetbrains.annotations.NotNull;
31 import java.util.UUID;
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)
38 @ColumnInfo(name = "name")
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) {
75 this.regularExpression = regularExpression;
76 this.uuid = UUID.randomUUID()
79 public TemplateHeader(TemplateHeader origin) {
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;
98 public String getUuid() {
101 public void setUuid(@NonNull String uuid) {
104 public boolean isFallback() {
107 public void setFallback(boolean fallback) {
108 isFallback = fallback;
110 public String getTestText() {
113 public void setTestText(String testText) {
114 this.testText = testText;
116 public Integer getTransactionDescriptionMatchGroup() {
117 return transactionDescriptionMatchGroup;
119 public void setTransactionDescriptionMatchGroup(Integer transactionDescriptionMatchGroup) {
120 this.transactionDescriptionMatchGroup = transactionDescriptionMatchGroup;
122 public Integer getTransactionCommentMatchGroup() {
123 return transactionCommentMatchGroup;
125 public void setTransactionCommentMatchGroup(Integer transactionCommentMatchGroup) {
126 this.transactionCommentMatchGroup = transactionCommentMatchGroup;
128 public Integer getDateYear() {
131 public void setDateYear(Integer dateYear) {
132 this.dateYear = dateYear;
134 public Integer getDateMonth() {
137 public void setDateMonth(Integer dateMonth) {
138 this.dateMonth = dateMonth;
140 public Integer getDateDay() {
143 public void setDateDay(Integer dateDay) {
144 this.dateDay = dateDay;
146 public long getId() {
149 public void setId(long id) {
153 public String getName() {
156 public void setName(@NonNull String name) {
160 public String getRegularExpression() {
161 return regularExpression;
163 public void setRegularExpression(@NonNull String regularExpression) {
164 this.regularExpression = regularExpression;
166 public String getTransactionDescription() {
167 return transactionDescription;
169 public void setTransactionDescription(String transactionDescription) {
170 this.transactionDescription = transactionDescription;
172 public String getTransactionComment() {
173 return transactionComment;
175 public void setTransactionComment(String transactionComment) {
176 this.transactionComment = transactionComment;
178 public Integer getDateYearMatchGroup() {
179 return dateYearMatchGroup;
181 public void setDateYearMatchGroup(Integer dateYearMatchGroup) {
182 this.dateYearMatchGroup = dateYearMatchGroup;
184 public Integer getDateMonthMatchGroup() {
185 return dateMonthMatchGroup;
187 public void setDateMonthMatchGroup(Integer dateMonthMatchGroup) {
188 this.dateMonthMatchGroup = dateMonthMatchGroup;
190 public Integer getDateDayMatchGroup() {
191 return dateDayMatchGroup;
193 public void setDateDayMatchGroup(Integer dateDayMatchGroup) {
194 this.dateDayMatchGroup = dateDayMatchGroup;
197 public boolean equals(@Nullable Object obj) {
200 if (!(obj instanceof TemplateHeader))
203 TemplateHeader o = (TemplateHeader) obj;
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);
219 public TemplateHeader createDuplicate() {
220 TemplateHeader dup = new TemplateHeader(this);