X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FAccountListItem.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FAccountListItem.java;h=1efe1962ce738583b1a1f45228b83ae2064f4a56;hp=dfd3d982011a105191f5e801bea2fcc5e276c4d6;hb=e687d63b107a215ba3b28e7028b9235cdf645bc0;hpb=18cc90fd341614bb30a321a7e790ff089828b76e diff --git a/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java b/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java index dfd3d982..1efe1962 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java @@ -34,12 +34,19 @@ public abstract class AccountListItem { else throw new RuntimeException("Unsupported sub-class " + this); } - @NotNull - public LedgerAccount getAccount() { - if (this instanceof Account) - return ((Account) this).account; - - throw new IllegalStateException(String.format("Item type is not Account, but %s", this)); + public boolean isAccount() { + return this instanceof Account; + } + public Account toAccount() { + assert isAccount(); + return ((Account) this); + } + public boolean isHeader() { + return this instanceof Header; + } + public Header toHeader() { + assert isHeader(); + return ((Header) this); } public enum Type {ACCOUNT, HEADER} @@ -59,6 +66,10 @@ public abstract class AccountListItem { ((Account) other).account.getAmountsString() .equals(account.getAmountsString()); } + @NotNull + public LedgerAccount getAccount() { + return account; + } } public static class Header extends AccountListItem {