From da49b6f42e6bbb9535b10f4c6d21e784c4106f4d Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Mon, 3 Dec 2018 21:20:59 +0000 Subject: [PATCH] Classes describing one transaction with its accounts --- .../ktnx/mobileledger/LedgerTransaction.java | 52 +++++++++++++++++++ .../mobileledger/LedgerTransactionItem.java | 45 ++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 app/src/main/java/net/ktnx/mobileledger/LedgerTransaction.java create mode 100644 app/src/main/java/net/ktnx/mobileledger/LedgerTransactionItem.java diff --git a/app/src/main/java/net/ktnx/mobileledger/LedgerTransaction.java b/app/src/main/java/net/ktnx/mobileledger/LedgerTransaction.java new file mode 100644 index 00000000..1690b936 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/LedgerTransaction.java @@ -0,0 +1,52 @@ +package net.ktnx.mobileledger; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +class LedgerTransaction { + private String date; + private String description; + private List items; + + LedgerTransaction(String date, String description) { + this.date = date; + this.description = description; + this.items = new ArrayList(); + } + + void add_item(LedgerTransactionItem item) { + items.add(item); + } + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Iterator getItemsIterator() { + return new Iterator() { + private int pointer = 0; + @Override + public boolean hasNext() { + return pointer < items.size(); + } + + @Override + public LedgerTransactionItem next() { + return hasNext() ? items.get(pointer++) : null; + } + }; + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/LedgerTransactionItem.java b/app/src/main/java/net/ktnx/mobileledger/LedgerTransactionItem.java new file mode 100644 index 00000000..4b3c6198 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/LedgerTransactionItem.java @@ -0,0 +1,45 @@ +package net.ktnx.mobileledger; + +class LedgerTransactionItem { + private String account_name; + private float amount; + private boolean amount_set; + + LedgerTransactionItem(String account_name, float amount) { + this.account_name = account_name; + this.amount = amount; + this.amount_set = true; + } + + public LedgerTransactionItem(String account_name) { + this.account_name = account_name; + } + + public String get_account_name() { + return account_name; + } + + public void set_account_name(String account_name) { + this.account_name = account_name; + } + + public float get_amount() { + if (!amount_set) + throw new IllegalStateException("Account amount is not set"); + + return amount; + } + + public void set_amount(float account_amount) { + this.amount = account_amount; + this.amount_set = true; + } + + public void reset_amount() { + this.amount_set = false; + } + + public boolean is_amount_set() { + return amount_set; + } +} -- 2.39.5