X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FLedgerTransactionAccount.java;h=4a83b185a00ac7da9046244fc1efd7b26762753b;hb=7ae5407090d9ffe2026775ba9e569014f879b54d;hp=ad6c94c26f2948368f06c725cd6913c91f9140d8;hpb=04f4085aad9982912b5061d3c0fb67892089816a;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java index ad6c94c2..4a83b185 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java @@ -23,9 +23,9 @@ public class LedgerTransactionAccount { private String accountName; private String shortAccountName; private float amount; - private boolean amountSet; + private boolean amountSet = false; private String currency; - + private String comment; public LedgerTransactionAccount(String accountName, float amount) { this(accountName, amount, null); } @@ -35,24 +35,36 @@ public class LedgerTransactionAccount { this.amountSet = true; this.currency = currency; } - public LedgerTransactionAccount(String accountName) { this.accountName = accountName; } - + public LedgerTransactionAccount(LedgerTransactionAccount origin) { + // copy constructor + setAccountName(origin.getAccountName()); + setComment(origin.getComment()); + if (origin.isAmountSet()) + setAmount(origin.getAmount()); + currency = origin.getCurrency(); + } + public String getComment() { + return comment; + } + public void setComment(String comment) { + this.comment = comment; + } public String getAccountName() { return accountName; } - public String getShortAccountName() { - return shortAccountName; - } public void setAccountName(String accountName) { this.accountName = accountName; shortAccountName = accountName.replaceAll("(?<=^|:)(.)[^:]+(?=:)", "$1"); } - + public String getShortAccountName() { + return shortAccountName; + } public float getAmount() { - if (!amountSet) throw new IllegalStateException("Account amount is not set"); + if (!amountSet) + throw new IllegalStateException("Account amount is not set"); return amount; } @@ -74,7 +86,8 @@ public class LedgerTransactionAccount { } @NonNull public String toString() { - if (!amountSet) return ""; + if (!amountSet) + return ""; StringBuilder sb = new StringBuilder(); if (currency != null) {