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