timing.core: simplify hashCode, equals and toString of AbstractCalledFunction
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.core / src / org / eclipse / tracecompass / internal / analysis / timing / core / callgraph / AbstractCalledFunction.java
index 0cf4b70392bb4d3c9ffb0e78d589c86c57dc589e..0d9833949eb34686b2bfa9beae2a67ec8e39f1c8 100644 (file)
@@ -52,8 +52,9 @@ abstract class AbstractCalledFunction implements ICalledFunction {
     private final List<ICalledFunction> fChildren = new ArrayList<>();
     private final @Nullable ICalledFunction fParent;
     protected long fSelfTime = 0;
+    private final int fProcessId;
 
-    public AbstractCalledFunction(long start, long end, int depth, @Nullable ICalledFunction parent) {
+    public AbstractCalledFunction(long start, long end, int depth, int processId, @Nullable ICalledFunction parent) {
         if (start > end) {
             throw new IllegalArgumentException(Messages.TimeError + "[" + start + "," + end + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         }
@@ -63,6 +64,7 @@ abstract class AbstractCalledFunction implements ICalledFunction {
         fParent = parent;
         // It'll be modified once we add a child to it
         fSelfTime = fEnd - fStart;
+        fProcessId = processId;
     }
 
     @Override
@@ -121,6 +123,11 @@ abstract class AbstractCalledFunction implements ICalledFunction {
         return fDepth;
     }
 
+    @Override
+    public int getProcessId() {
+        return fProcessId;
+    }
+
     @Override
     public int compareTo(@Nullable ISegment o) {
         if (o == null) {
@@ -131,21 +138,12 @@ abstract class AbstractCalledFunction implements ICalledFunction {
 
     @Override
     public String toString() {
-        return new String("[" + String.valueOf(fStart) + ", " + String.valueOf(fEnd) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        return '[' + String.valueOf(fStart) + ", " + String.valueOf(fEnd) + ']'; //$NON-NLS-1$
     }
 
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + fDepth;
-        result = prime * result + (int) (fEnd ^ (fEnd >>> 32));
-        ICalledFunction parent = fParent;
-        result = prime * result + ((parent == null) ? 0 : parent.hashCode());
-        result = prime * result + (int) (fSelfTime ^ (fSelfTime >>> 32));
-        result = prime * result + (int) (fStart ^ (fStart >>> 32));
-        result = prime * result + getSymbol().hashCode();
-        return result;
+        return Objects.hash(fDepth, fEnd, fParent, fSelfTime, fStart, getSymbol());
     }
 
     @Override
@@ -166,19 +164,15 @@ abstract class AbstractCalledFunction implements ICalledFunction {
         if (fEnd != other.fEnd) {
             return false;
         }
-        if (fParent == null) {
-            if (other.fParent != null) {
-                return false;
-            }
-        } else if (!Objects.equals(fParent, other.fParent)) {
-            return false;
-        }
         if (fSelfTime != other.fSelfTime) {
             return false;
         }
         if (fStart != other.fStart) {
             return false;
         }
+        if (!Objects.equals(fParent, other.getParent())) {
+            return false;
+        }
         if (!Objects.equals(getSymbol(), other.getSymbol())) {
             return false;
         }
This page took 0.029916 seconds and 5 git commands to generate.