]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java
no direct interface to ObservableList's value
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / LedgerAccount.java
index f632bba94311d97485e6f98584776c9176095bd6..b0593f992c4b43d88369d36f1e8e7a07ddb07101 100644 (file)
@@ -23,6 +23,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 
 public class LedgerAccount {
     static Pattern reHigherAccount = Pattern.compile("^[^:]+:");
@@ -48,6 +49,17 @@ public class LedgerAccount {
         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
@@ -56,9 +68,9 @@ public class LedgerAccount {
 
         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;