From f11c8a93f92f5a372ea423cdf2d3d9629bd5f45f Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Mon, 8 Feb 2021 05:49:33 +0000 Subject: [PATCH] AccountRow: copy constructor --- .../mobileledger/model/TemplateDetailsItem.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java b/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java index 7c333866..d0a6e240 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java @@ -226,6 +226,11 @@ abstract public class TemplateDetailsItem { result.setValue(initialValue); return result; } + public void copyFrom(@NonNull PossiblyMatchedValue origin) { + literalValue = origin.literalValue; + value = origin.value; + matchGroup = origin.matchGroup; + } public T getValue() { if (!literalValue) throw new IllegalStateException("Value is not literal"); @@ -287,9 +292,19 @@ abstract public class TemplateDetailsItem { PossiblyMatchedValue.withLiteralFloat(null); private final PossiblyMatchedValue currency = new PossiblyMatchedValue<>(); private boolean negateAmount; - private AccountRow() { + public AccountRow() { super(Type.ACCOUNT_ITEM); } + public AccountRow(AccountRow origin) { + super(Type.ACCOUNT_ITEM); + id = origin.id; + position = origin.position; + accountName.copyFrom(origin.accountName); + accountComment.copyFrom(origin.accountComment); + amount.copyFrom(origin.amount); + currency.copyFrom(origin.currency); + negateAmount = origin.negateAmount; + } public boolean isNegateAmount() { return negateAmount; } -- 2.39.2