summaryrefslogtreecommitdiffstats
path: root/telephony/java/android/telephony/CellIdentityCdma.java
diff options
context:
space:
mode:
authorBrian Williammee <bwill@google.com>2014-08-29 17:31:22 -0700
committerBrian Williammee <bwill@google.com>2014-09-10 17:06:09 -0700
commit7d1d2e39f382416ffa8db8771c83e4f9e2f53adc (patch)
tree8105734b682ef1a7aa69ea3b0c3edb670b3ce94e /telephony/java/android/telephony/CellIdentityCdma.java
parenta98f7d715d12fe1dc4b9d06c6e5cc152f6e3e347 (diff)
downloadframeworks_base-7d1d2e39f382416ffa8db8771c83e4f9e2f53adc.zip
frameworks_base-7d1d2e39f382416ffa8db8771c83e4f9e2f53adc.tar.gz
frameworks_base-7d1d2e39f382416ffa8db8771c83e4f9e2f53adc.tar.bz2
Improve equals and hashCode in CellIdentityXxx methods
The equals methods were a lot of dead code that boiled down to seeing if two references pointed to the same object. The hashCode methods were likely to result in collisions on unequal objects. Bug: 10328291 Change-Id: I4bd93efd1f4a34e9dec55ac05868df37368abd6a
Diffstat (limited to 'telephony/java/android/telephony/CellIdentityCdma.java')
-rw-r--r--telephony/java/android/telephony/CellIdentityCdma.java30
1 files changed, 15 insertions, 15 deletions
diff --git a/telephony/java/android/telephony/CellIdentityCdma.java b/telephony/java/android/telephony/CellIdentityCdma.java
index dbd48d9..b39b4c7 100644
--- a/telephony/java/android/telephony/CellIdentityCdma.java
+++ b/telephony/java/android/telephony/CellIdentityCdma.java
@@ -20,6 +20,8 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.telephony.Rlog;
+import java.util.Objects;
+
/**
* CellIdentity is to represent a unique CDMA cell
*/
@@ -137,27 +139,25 @@ public final class CellIdentityCdma implements Parcelable {
@Override
public int hashCode() {
- int primeNum = 31;
- return (mNetworkId * primeNum) + (mSystemId * primeNum) + (mBasestationId * primeNum) +
- (mLatitude * primeNum) + (mLongitude * primeNum);
+ return Objects.hash(mNetworkId, mSystemId, mBasestationId, mLatitude, mLongitude);
}
@Override
public boolean equals(Object other) {
- if (super.equals(other)) {
- try {
- CellIdentityCdma o = (CellIdentityCdma)other;
- return mNetworkId == o.mNetworkId &&
- mSystemId == o.mSystemId &&
- mBasestationId == o.mBasestationId &&
- mLatitude == o.mLatitude &&
- mLongitude == o.mLongitude;
- } catch (ClassCastException e) {
- return false;
- }
- } else {
+ if (this == other) {
+ return true;
+ }
+
+ if (!(other instanceof CellIdentityCdma)) {
return false;
}
+
+ CellIdentityCdma o = (CellIdentityCdma) other;
+ return mNetworkId == o.mNetworkId &&
+ mSystemId == o.mSystemId &&
+ mBasestationId == o.mBasestationId &&
+ mLatitude == o.mLatitude &&
+ mLongitude == o.mLongitude;
}
@Override