2 * Copyright © 2019 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.
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.
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/>.
18 package net.ktnx.mobileledger.model;
20 import androidx.annotation.NonNull;
22 public class LedgerTransactionAccount {
23 private String accountName;
24 private String shortAccountName;
26 private boolean amountSet = false;
27 private String currency;
28 private String comment;
29 public LedgerTransactionAccount(String accountName, float amount, String currency,
31 this.setAccountName(accountName);
33 this.amountSet = true;
34 this.currency = currency;
35 this.comment = comment;
37 public LedgerTransactionAccount(String accountName) {
38 this.accountName = accountName;
40 public LedgerTransactionAccount(LedgerTransactionAccount origin) {
42 setAccountName(origin.getAccountName());
43 setComment(origin.getComment());
44 if (origin.isAmountSet())
45 setAmount(origin.getAmount());
46 currency = origin.getCurrency();
48 public String getComment() {
51 public void setComment(String comment) {
52 this.comment = comment;
54 public String getAccountName() {
57 public void setAccountName(String accountName) {
58 this.accountName = accountName;
59 shortAccountName = accountName.replaceAll("(?<=^|:)(.)[^:]+(?=:)", "$1");
61 public String getShortAccountName() {
62 return shortAccountName;
64 public float getAmount() {
66 throw new IllegalStateException("Account amount is not set");
71 public void setAmount(float account_amount) {
72 this.amount = account_amount;
73 this.amountSet = true;
76 public void resetAmount() {
77 this.amountSet = false;
80 public boolean isAmountSet() {
83 public String getCurrency() {
87 public String toString() {
91 StringBuilder sb = new StringBuilder();
92 if (currency != null) {
96 sb.append(String.format("%,1.2f", amount));