]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionItem.java
whitespace
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / LedgerTransactionItem.java
index ff19a450251aef1077855d2862f21502cb42c0e8..108425846dd7d16baa1036870593e716b36dccc5 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.ktnx.mobileledger.model;
 
+import android.support.annotation.NonNull;
+
 public class LedgerTransactionItem {
     private String accountName;
     private float amount;
@@ -40,14 +42,18 @@ public class LedgerTransactionItem {
     public String getAccountName() {
         return accountName;
     }
+    public String getShortAccountName() {
+        String result = accountName;
+        result = result.replaceAll("(?<=^|:)(.)[^:]+(?=:)", "$1");
+        return result;
+    }
 
     public void setAccountName(String accountName) {
         this.accountName = accountName;
     }
 
     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;
     }
@@ -67,4 +73,17 @@ public class LedgerTransactionItem {
     public String getCurrency() {
         return currency;
     }
+    @NonNull
+    public String toString() {
+        if (!amountSet) return "";
+
+        StringBuilder sb = new StringBuilder();
+        if (currency != null) {
+            sb.append(currency);
+            sb.append(' ');
+        }
+        sb.append(String.format("%,1.2f", amount));
+
+        return sb.toString();
+    }
 }