From f782210abf37116018833b1d9858e087f497f59e Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 24 Mar 2019 11:40:56 +0200 Subject: [PATCH 1/1] LedgerAccount: override hashCode() and equals() to enable proper location in collections --- .../net/ktnx/mobileledger/model/LedgerAccount.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java index f632bba9..c2ad2c2f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java @@ -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(); 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 -- 2.39.2