import java.util.regex.Pattern;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
public class LedgerAccount {
static Pattern reHigherAccount = Pattern.compile("^[^:]+:");
private boolean expanded;
private List<LedgerAmount> amounts;
private boolean hasSubAccounts;
+ private boolean amountsExpanded;
public LedgerAccount(String name) {
this.setName(name);
this.amounts = new ArrayList<LedgerAmount>();
this.addAmount(amount);
}
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+ @Override
+ public boolean equals(@Nullable Object obj) {
+ if (obj == null) return false;
+
+ return obj.getClass().equals(this.getClass()) &&
+ name.equals(((LedgerAccount) obj).getName());
+ }
// an account is visible if:
// - it is starred (not hidden by a star)
// - and it has an expanded parent or is a top account
if (level == 0) return true;
- return isVisible(Data.accounts.get());
+ return isVisible(Data.accounts);
}
- public boolean isVisible(ArrayList<LedgerAccount> list) {
+ public boolean isVisible(List<LedgerAccount> list) {
for (LedgerAccount acc : list) {
if (acc.isParentOf(this)) {
if (!acc.isExpanded()) return false;
public void addAmount(float amount) {
this.addAmount(amount, null);
}
-
+ public int getAmountCount() { return (amounts != null) ? amounts.size() : 0; }
public String getAmountsString() {
if ((amounts == null) || amounts.isEmpty()) return "";
return builder.toString();
}
+ public String getAmountsString(int limit) {
+ if ((amounts == null) || amounts.isEmpty()) return "";
+ int included = 0;
+ StringBuilder builder = new StringBuilder();
+ for (LedgerAmount amount : amounts) {
+ String amt = amount.toString();
+ if (builder.length() > 0) builder.append('\n');
+ builder.append(amt);
+ included++;
+ if (included == limit) break;
+ }
+
+ return builder.toString();
+ }
public int getLevel() {
return level;
}
public void removeAmounts() {
if (amounts != null) amounts.clear();
}
+ public boolean amountsExpanded() { return amountsExpanded; }
+ public void setAmountsExpanded(boolean flag) { amountsExpanded = flag; }
+ public void toggleAmountsExpanded() { amountsExpanded = !amountsExpanded; }
+
}