Override Object#hashCode and add missing switch type.
Override Object#hashCode when we override Object#equals.
Add missing switch type to handle all possible values.
Test: Passed art/ahat_unit_tests using Forrest
Change-Id: I22b2b3af94cd6179340de8d865b9787393de17ea
diff --git a/tools/ahat/src/main/com/android/ahat/heapdump/DiffedFieldValue.java b/tools/ahat/src/main/com/android/ahat/heapdump/DiffedFieldValue.java
index 8de337e..fcb92a9 100644
--- a/tools/ahat/src/main/com/android/ahat/heapdump/DiffedFieldValue.java
+++ b/tools/ahat/src/main/com/android/ahat/heapdump/DiffedFieldValue.java
@@ -114,6 +114,10 @@
this.status = status;
}
+ @Override public int hashCode() {
+ return Objects.hash(name, type, current, baseline, status);
+ }
+
@Override
public boolean equals(Object otherObject) {
if (otherObject instanceof DiffedFieldValue) {
diff --git a/tools/ahat/src/main/com/android/ahat/heapdump/Parser.java b/tools/ahat/src/main/com/android/ahat/heapdump/Parser.java
index 4e7cd43..c7f7b4b 100644
--- a/tools/ahat/src/main/com/android/ahat/heapdump/Parser.java
+++ b/tools/ahat/src/main/com/android/ahat/heapdump/Parser.java
@@ -32,6 +32,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
/**
* Provides methods for parsing heap dumps.
@@ -509,6 +510,7 @@
obj.initialize(data);
break;
}
+ default: throw new AssertionError("unsupported enum member");
}
break;
}
@@ -736,6 +738,10 @@
return String.format("0x%08x", mId);
}
+ @Override public int hashCode() {
+ return Objects.hash(mId);
+ }
+
@Override public boolean equals(Object other) {
if (other instanceof DeferredInstanceValue) {
DeferredInstanceValue value = (DeferredInstanceValue)other;
diff --git a/tools/ahat/src/main/com/android/ahat/heapdump/Size.java b/tools/ahat/src/main/com/android/ahat/heapdump/Size.java
index a4593e1..b721bac 100644
--- a/tools/ahat/src/main/com/android/ahat/heapdump/Size.java
+++ b/tools/ahat/src/main/com/android/ahat/heapdump/Size.java
@@ -16,6 +16,8 @@
package com.android.ahat.heapdump;
+import java.util.Objects;
+
/**
* Used to represent how much space an instance takes up.
* An abstraction is introduced rather than using a long directly in order to
@@ -110,6 +112,11 @@
return new Size(mJavaSize, mRegisteredNativeSize + size);
}
+ @Override
+ public int hashCode() {
+ return Objects.hash(mJavaSize, mRegisteredNativeSize);
+ }
+
@Override public boolean equals(Object other) {
if (other instanceof Size) {
Size s = (Size)other;
diff --git a/tools/ahat/src/main/com/android/ahat/heapdump/Value.java b/tools/ahat/src/main/com/android/ahat/heapdump/Value.java
index d78f95b..5e48dca 100644
--- a/tools/ahat/src/main/com/android/ahat/heapdump/Value.java
+++ b/tools/ahat/src/main/com/android/ahat/heapdump/Value.java
@@ -16,6 +16,8 @@
package com.android.ahat.heapdump;
+import java.util.Objects;
+
/**
* A Java instance or primitive value from a parsed heap dump.
* Note: To save memory, a null Value is used to represent a null Java
@@ -226,6 +228,9 @@
}
@Override
+ public abstract int hashCode();
+
+ @Override
public abstract boolean equals(Object other);
private static class BooleanValue extends Value {
@@ -245,6 +250,10 @@
return Boolean.toString(mBool);
}
+ @Override public int hashCode() {
+ return Objects.hash(mBool);
+ }
+
@Override public boolean equals(Object other) {
if (other instanceof BooleanValue) {
BooleanValue value = (BooleanValue)other;
@@ -276,6 +285,10 @@
return Byte.toString(mByte);
}
+ @Override public int hashCode() {
+ return Objects.hash(mByte);
+ }
+
@Override public boolean equals(Object other) {
if (other instanceof ByteValue) {
ByteValue value = (ByteValue)other;
@@ -307,6 +320,10 @@
return Character.toString(mChar);
}
+ @Override public int hashCode() {
+ return Objects.hash(mChar);
+ }
+
@Override public boolean equals(Object other) {
if (other instanceof CharValue) {
CharValue value = (CharValue)other;
@@ -333,6 +350,10 @@
return Double.toString(mDouble);
}
+ @Override public int hashCode() {
+ return Objects.hash(mDouble);
+ }
+
@Override public boolean equals(Object other) {
if (other instanceof DoubleValue) {
DoubleValue value = (DoubleValue)other;
@@ -359,6 +380,10 @@
return Float.toString(mFloat);
}
+ @Override public int hashCode() {
+ return Objects.hash(mFloat);
+ }
+
@Override public boolean equals(Object other) {
if (other instanceof FloatValue) {
FloatValue value = (FloatValue)other;
@@ -401,6 +426,10 @@
return InstanceValue.pack(mInstance.getBaseline());
}
+ @Override public int hashCode() {
+ return Objects.hash(mInstance);
+ }
+
@Override public boolean equals(Object other) {
if (other instanceof InstanceValue) {
InstanceValue value = (InstanceValue)other;
@@ -437,6 +466,10 @@
return Integer.toString(mInt);
}
+ @Override public int hashCode() {
+ return Objects.hash(mInt);
+ }
+
@Override public boolean equals(Object other) {
if (other instanceof IntValue) {
IntValue value = (IntValue)other;
@@ -473,6 +506,10 @@
return Long.toString(mLong);
}
+ @Override public int hashCode() {
+ return Objects.hash(mLong);
+ }
+
@Override public boolean equals(Object other) {
if (other instanceof LongValue) {
LongValue value = (LongValue)other;
@@ -499,6 +536,10 @@
return Short.toString(mShort);
}
+ @Override public int hashCode() {
+ return Objects.hash(mShort);
+ }
+
@Override public boolean equals(Object other) {
if (other instanceof ShortValue) {
ShortValue value = (ShortValue)other;