diff options
| author | Steve McKay <smckay@google.com> | 2015-07-22 11:42:14 -0700 |
|---|---|---|
| committer | Steve McKay <smckay@google.com> | 2015-07-22 11:53:14 -0700 |
| commit | 3b409d01b9511e196ca5ad746c44fd93925ab1b8 (patch) | |
| tree | 9510d29e1dfd8c666f2ce0176ead1442b4332b45 /core/java/android/util/SparseBooleanArray.java | |
| parent | 0ab6b0e8246748719a52f5b233ef3a85c4f8f324 (diff) | |
Push equals impl into SparseBooleanArray.
Also, implement hashcode, because it is naughty to not.
Change-Id: I2042dac6840cf07027871783a7b6763578fa805d
Diffstat (limited to 'core/java/android/util/SparseBooleanArray.java')
| -rw-r--r-- | core/java/android/util/SparseBooleanArray.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/core/java/android/util/SparseBooleanArray.java b/core/java/android/util/SparseBooleanArray.java index 8fd8226da6ac..4f76463a653e 100644 --- a/core/java/android/util/SparseBooleanArray.java +++ b/core/java/android/util/SparseBooleanArray.java @@ -237,6 +237,41 @@ public class SparseBooleanArray implements Cloneable { mSize++; } + @Override + public int hashCode() { + int hashCode = mSize; + for (int i = 0; i < mSize; i++) { + hashCode = 31 * hashCode + mKeys[i] | (mValues[i] ? 1 : 0); + } + return hashCode; + } + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + + if (!(that instanceof SparseBooleanArray)) { + return false; + } + + SparseBooleanArray other = (SparseBooleanArray) that; + if (mSize != other.mSize) { + return false; + } + + for (int i = 0; i < mSize; i++) { + if (mKeys[i] != other.mKeys[i]) { + return false; + } + if (mValues[i] != other.mValues[i]) { + return false; + } + } + return true; + } + /** * {@inheritDoc} * |
