Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / experiment / TmfExperimentContext.java
index 1f4d39a8e0cb2c142bf2964509a1a5356b1669e7..3d4981cbc118f04d045dc1f05e3a39f8e12df4b8 100644 (file)
@@ -20,14 +20,33 @@ import org.eclipse.linuxtools.tmf.trace.TmfContext;
 /**
  * <b><u>TmfExperimentContext</u></b>
  * <p>
- * Implement me. Please.
+ * The experiment keeps track of the next event from each of its traces so
+ * it can pick the next one in chronological order.
+ * <p>
+ * This implies that the "next" event from each trace has already been
+ * read and that we at least know its timestamp. This doesn't imply that a
+ * full parse of the event content was performed (read: LTTng works like 
+ * this).
+ * <p>
+ * The last trace refers to the trace from which the last event was
+ * "consumed" at the experiment level.
  */
 public class TmfExperimentContext extends TmfContext {
 
+       // ------------------------------------------------------------------------
+       // Constants
+       // ------------------------------------------------------------------------
+       
+        public static final int NO_TRACE = -1;
+
+       // ------------------------------------------------------------------------
+       // Attributes
+       // ------------------------------------------------------------------------
+
        private ITmfTrace[]  fTraces = new ITmfTrace[0];
        private TmfContext[] fContexts;
        private TmfEvent[]   fEvents;
-       private int lastIndex;
+       private int lastTraceRead;
 
        // ------------------------------------------------------------------------
        // Constructors
@@ -40,17 +59,19 @@ public class TmfExperimentContext extends TmfContext {
                fEvents   = new TmfEvent[fTraces.length];
 
                ITmfLocation<?>[] locations = new ITmfLocation[fTraces.length];
+               long[] ranks = new long[fTraces.length];
                long rank = 0;
                for (int i = 0; i < fTraces.length; i++) {
                        if (contexts[i] != null) {
                                locations[i] = contexts[i].getLocation();
+                               ranks[i] = contexts[i].getRank();
                                rank += contexts[i].getRank();
                        }
                }
                
-               setLocation(new TmfExperimentLocation(locations));
+               setLocation(new TmfExperimentLocation(new TmfLocationArray(locations), ranks));
                setRank(rank);
-               lastIndex = -1;
+               lastTraceRead = NO_TRACE;
        }
 
        public TmfExperimentContext(ITmfTrace[] traces) {
@@ -60,9 +81,10 @@ public class TmfExperimentContext extends TmfContext {
        public TmfExperimentContext(TmfExperimentContext other) {
                this(other.fTraces, other.cloneContexts());
                fEvents = other.fEvents;
-               setLocation(other.getLocation().clone());
+               if (other.getLocation() != null)
+                       setLocation(other.getLocation().clone());
                setRank(other.getRank());
-               setLastTrace(other.lastIndex);
+               setLastTrace(other.lastTraceRead);
        }
 
        private TmfContext[] cloneContexts() {
@@ -89,11 +111,41 @@ public class TmfExperimentContext extends TmfContext {
        }
 
        public int getLastTrace() {
-               return lastIndex;
+               return lastTraceRead;
        }
 
        public void setLastTrace(int newIndex) {
-               lastIndex = newIndex;
+               lastTraceRead = newIndex;
        }
 
+       // ------------------------------------------------------------------------
+       // Object
+       // ------------------------------------------------------------------------
+
+    @Override
+    public int hashCode() {
+               int result = 17;
+       for (int i = 0; i < fTraces.length; i++) {
+               result = 37 * result + fTraces[i].hashCode();
+               result = 37 * result + fContexts[i].hashCode();
+       }
+       return result;
+    }
+    @Override
+    public boolean equals(Object other) {
+       if (!(other instanceof TmfExperimentContext)) {
+               return false;
+       }
+       TmfExperimentContext o = (TmfExperimentContext) other;
+       boolean isEqual = true;
+       int i = 0;
+       while (isEqual && i < fTraces.length) {
+               isEqual &= fTraces[i].equals(o.fTraces[i]);
+               isEqual &= fContexts[i].equals(o.fContexts[i]);
+               i++;
+       }
+       return isEqual;
+    }
 }
This page took 0.025484 seconds and 5 git commands to generate.