X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FLedgerTransactionAccount.java;h=4468724e5f3771490ce81221ec8d480ce30f3817;hb=2d09e6a32395295afec7deb5561b7eb2a82f8efc;hp=2e5e9c4990163e81fe0e2719adb098e3df573725;hpb=09e26d2279484b4dfe0de218b05f075362fff4b5;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 2e5e9c49..4468724e 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java @@ -1,5 +1,5 @@ /* - * Copyright © 2018 Damyan Ivanov. + * Copyright © 2019 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -19,62 +19,80 @@ package net.ktnx.mobileledger.model; import androidx.annotation.NonNull; +import net.ktnx.mobileledger.utils.Misc; + public class LedgerTransactionAccount { private String accountName; private String shortAccountName; private float amount; - private boolean amountSet; + private boolean amountSet = false; private String currency; - - public LedgerTransactionAccount(String accountName, float amount) { - this(accountName, amount, null); - } - public LedgerTransactionAccount(String accountName, float amount, String currency) { + private String comment; + public LedgerTransactionAccount(String accountName, float amount, String currency, + String comment) { this.setAccountName(accountName); this.amount = amount; this.amountSet = true; - this.currency = currency; + this.currency = Misc.emptyIsNull(currency); + this.comment = Misc.emptyIsNull(comment); } - public LedgerTransactionAccount(String accountName) { this.accountName = accountName; } - + public LedgerTransactionAccount(String accountName, String currency) { + this.accountName = accountName; + this.currency = Misc.emptyIsNull(currency); + } + 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; } - public void setAmount(float account_amount) { this.amount = account_amount; this.amountSet = true; } - public void resetAmount() { this.amountSet = false; } - public boolean isAmountSet() { return amountSet; } public String getCurrency() { return currency; } + public void setCurrency(String currency) { + this.currency = Misc.emptyIsNull(currency); + } @NonNull public String toString() { - if (!amountSet) return ""; + if (!amountSet) + return ""; StringBuilder sb = new StringBuilder(); if (currency != null) {