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