package net.ktnx.mobileledger.model;
+import android.support.annotation.NonNull;
+
public class LedgerTransactionItem {
private String accountName;
private float amount;
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;
}
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();
+ }
}