ss: Properly implement hashCode/equals in HTInterval
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Mon, 27 Jun 2016 20:46:13 +0000 (16:46 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Wed, 29 Jun 2016 21:04:57 +0000 (17:04 -0400)
The equals() was wrongly calling .compareTo(), which only
checks the end times, not the whole object.

Change-Id: I235d01b3cd19a668e0808233eedcd5c1f50c5b57
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/76059
Reviewed-by: Hudson CI
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/internal/statesystem/core/backend/historytree/HTInterval.java

index 8b2139a8bcf2ff991cc8ff61f01cc1b79e44d70b..925a647194e9afc2f246eb28102c153125acd7f4 100644 (file)
@@ -17,6 +17,7 @@ package org.eclipse.tracecompass.internal.statesystem.core.backend.historytree;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.util.Objects;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.internal.provisional.statesystem.core.statevalue.CustomStateValue;
@@ -348,17 +349,26 @@ public final class HTInterval implements ITmfStateInterval, Comparable<HTInterva
     }
 
     @Override
-    public boolean equals(Object other) {
-        if (other instanceof HTInterval &&
-                this.compareTo((HTInterval) other) == 0) {
+    public boolean equals(Object obj) {
+        if (this == obj) {
             return true;
         }
-        return false;
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        HTInterval other = (HTInterval) obj;
+        return (start == other.start &&
+                end == other.end &&
+                attribute == other.attribute &&
+                sv.equals(other.sv));
     }
 
     @Override
     public int hashCode() {
-        return super.hashCode();
+        return Objects.hash(start, end, attribute, sv);
     }
 
     @Override
This page took 0.025697 seconds and 5 git commands to generate.