]> git.ktnx.net Git - mobile-ledger.git/commitdiff
Classes describing one transaction with its accounts
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 3 Dec 2018 21:20:59 +0000 (21:20 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 3 Dec 2018 21:20:59 +0000 (21:20 +0000)
app/src/main/java/net/ktnx/mobileledger/LedgerTransaction.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/LedgerTransactionItem.java [new file with mode: 0644]

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 (file)
index 0000000..1690b93
--- /dev/null
@@ -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<LedgerTransactionItem> items;
+
+    LedgerTransaction(String date, String description) {
+        this.date = date;
+        this.description = description;
+        this.items = new ArrayList<LedgerTransactionItem>();
+    }
+
+    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<LedgerTransactionItem> getItemsIterator() {
+        return new Iterator<LedgerTransactionItem>() {
+            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 (file)
index 0000000..4b3c619
--- /dev/null
@@ -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;
+    }
+}