From: Damyan Ivanov Date: Fri, 5 Feb 2021 05:45:21 +0000 (+0200) Subject: copy-constructors for TemplateHeader/TemplateAccount/TemplateWithAccounts X-Git-Tag: v0.17.0~160 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=5a514f5f9ee23a57fdd135f265f7fa095b463773;p=mobile-ledger.git copy-constructors for TemplateHeader/TemplateAccount/TemplateWithAccounts --- diff --git a/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java b/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java index 8651e3fe..f697b4dd 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java @@ -69,6 +69,20 @@ public class TemplateAccount extends TemplateBase { this.templateId = templateId; this.position = position; } + public TemplateAccount(TemplateAccount o) { + id = o.id; + templateId = o.templateId; + accountName = o.accountName; + position = o.position; + accountNameMatchGroup = o.accountNameMatchGroup; + currency = o.currency; + currencyMatchGroup = o.currencyMatchGroup; + amount = o.amount; + amountMatchGroup = o.amountMatchGroup; + accountComment = o.accountComment; + accountCommentMatchGroup = o.accountCommentMatchGroup; + negateAmount = o.negateAmount; + } public Long getId() { return id; } diff --git a/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java b/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java index 5422767f..68a11232 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateHeader.java @@ -66,6 +66,22 @@ public class TemplateHeader extends TemplateBase { this.name = name; this.regularExpression = regularExpression; } + public TemplateHeader(TemplateHeader origin) { + id = origin.id; + name = origin.name; + regularExpression = origin.regularExpression; + testText = origin.testText; + transactionDescription = origin.transactionDescription; + transactionDescriptionMatchGroup = origin.transactionDescriptionMatchGroup; + transactionComment = origin.transactionComment; + transactionCommentMatchGroup = origin.transactionCommentMatchGroup; + dateYear = origin.dateYear; + dateYearMatchGroup = origin.dateYearMatchGroup; + dateMonth = origin.dateMonth; + dateMonthMatchGroup = origin.dateMonthMatchGroup; + dateDay = origin.dateDay; + dateDayMatchGroup = origin.dateDayMatchGroup; + } public String getTestText() { return testText; } diff --git a/app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java b/app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java index a40ecae9..60d56a5f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java @@ -20,6 +20,7 @@ package net.ktnx.mobileledger.db; import androidx.room.Embedded; import androidx.room.Relation; +import java.util.ArrayList; import java.util.List; public class TemplateWithAccounts { @@ -28,6 +29,16 @@ public class TemplateWithAccounts { @Relation(parentColumn = "id", entityColumn = "template_id") public List accounts; + public static TemplateWithAccounts from(TemplateWithAccounts o) { + TemplateWithAccounts result = new TemplateWithAccounts(); + result.header = new TemplateHeader(o.header); + result.accounts = new ArrayList<>(); + for (TemplateAccount acc : o.accounts) { + result.accounts.add(new TemplateAccount(acc)); + } + + return result; + } public Long getId() { return header.getId(); }