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=83b349e2f67cf58bfa019c9057faaf13c95bbf23;hpb=998dd32a089d199a2569069415755eb3169b35b0;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 83b349e2..4a83b185 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 @@ -17,15 +17,15 @@ package net.ktnx.mobileledger.model; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; 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) {