Remove the generic location (replace by Comparable)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / trace / TmfExperimentContext.java
index 716b9a87b4c4c8317f1399d404c1357281162936..236e3a2ddd17335440733cd38b2a0e74289c9d0b 100644 (file)
@@ -8,7 +8,7 @@
  *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
- * Francois Chouinard - Put in shape for 1.0
+ *   Francois Chouinard - Put in shape for 1.0
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.tmf.core.trace;
@@ -32,7 +32,7 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
  * The last trace refers to the trace from which the last event was "consumed"
  * at the experiment level.
  */
-public class TmfExperimentContext extends TmfContext implements Cloneable {
+public class TmfExperimentContext extends TmfContext {
 
     // ------------------------------------------------------------------------
     // Constants
@@ -56,35 +56,46 @@ public class TmfExperimentContext extends TmfContext implements Cloneable {
     // ------------------------------------------------------------------------
 
     /**
+     * Standard constructor
+     *
      * @param contexts
+     *            The matching context for each trace in the experiment
      */
     public TmfExperimentContext(final ITmfContext[] contexts) {
         super();
         fContexts = contexts;
         fEvents = new ITmfEvent[fContexts.length];
-        final ITmfLocation<?>[] locations = new ITmfLocation[fContexts.length];
+        final ITmfLocation[] locations = new ITmfLocation[fContexts.length];
+
+        setLocation(new TmfExperimentLocation(new TmfLocationArray(locations.clone())));
+
         final long[] ranks = new long[fContexts.length];
         long rank = 0;
-        for (int i = 0; i < fContexts.length; i++)
+        for (int i = 0; i < fContexts.length; i++) {
             if (contexts[i] != null) {
                 locations[i] = contexts[i].getLocation();
                 ranks[i] = contexts[i].getRank();
                 rank += contexts[i].getRank();
             }
+        }
 
-        setLocation(new TmfExperimentLocation(new TmfLocationArray(locations)));
+//        setLocation(new TmfExperimentLocation(new TmfLocationArray(locations)));
         setRank(rank);
         fLastTraceRead = NO_TRACE;
     }
 
     /**
+     * Copy constructor
+     *
      * @param other
+     *            The experiment context to copy
      */
     public TmfExperimentContext(final TmfExperimentContext other) {
         this(other.cloneContexts());
         fEvents = other.fEvents;
-        if (other.getLocation() != null)
+        if (other.getLocation() != null) {
             setLocation(other.getLocation().clone());
+        }
         setRank(other.getRank());
         setLastTrace(other.fLastTraceRead);
     }
@@ -104,15 +115,17 @@ public class TmfExperimentContext extends TmfContext implements Cloneable {
 
     private ITmfContext[] cloneContexts() {
         final ITmfContext[] contexts = new ITmfContext[fContexts.length];
-        for (int i = 0; i < fContexts.length; i++)
+        for (int i = 0; i < fContexts.length; i++) {
             contexts[i] = (fContexts[i] != null) ? fContexts[i].clone() : null;
+        }
         return contexts;
     }
 
     private ITmfEvent[] cloneEvents() {
         final ITmfEvent[] events = new ITmfEvent[fEvents.length];
-        for (int i = 0; i < fEvents.length; i++)
+        for (int i = 0; i < fEvents.length; i++) {
             events[i] = (fEvents[i] != null) ? fEvents[i].clone() : null;
+        }
         return events;
     }
 
@@ -120,18 +133,40 @@ public class TmfExperimentContext extends TmfContext implements Cloneable {
     // Accessors
     // ------------------------------------------------------------------------
 
+    /**
+     * Get the trace contexts composing this experiment context.
+     *
+     * @return The array of trace contexts
+     */
     public ITmfContext[] getContexts() {
         return fContexts;
     }
 
+    /**
+     * Get the trace events located at this experiment context's location.
+     *
+     * @return The array of trace events
+     */
     public ITmfEvent[] getEvents() {
         return fEvents;
     }
 
+    /**
+     * Get the index of the trace that was last read (so the trace whose
+     * current context will match this experiment's).
+     *
+     * @return The index of the trace
+     */
     public int getLastTrace() {
         return fLastTraceRead;
     }
 
+    /**
+     * Set the last trace read index
+     *
+     * @param newIndex
+     *            The new value to assign
+     */
     public void setLastTrace(final int newIndex) {
         fLastTraceRead = newIndex;
     }
@@ -151,12 +186,15 @@ public class TmfExperimentContext extends TmfContext implements Cloneable {
 
     @Override
     public boolean equals(final Object other) {
-        if (this == other)
+        if (this == other) {
             return true;
-        if (!super.equals(other))
+        }
+        if (!super.equals(other)) {
             return false;
-        if (!(other instanceof TmfExperimentContext))
+        }
+        if (!(other instanceof TmfExperimentContext)) {
             return false;
+        }
         final TmfExperimentContext o = (TmfExperimentContext) other;
         boolean isEqual = true;
         int i = 0;
@@ -167,4 +205,23 @@ public class TmfExperimentContext extends TmfContext implements Cloneable {
         return isEqual;
     }
 
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        StringBuilder sb = new StringBuilder("TmfExperimentContext [\n");
+        sb.append("\tfLocation=" + getLocation() + ", fRank=" + getRank() + "\n");
+        sb.append("\tfContexts=[");
+        for (int i = 0; i < fContexts.length; i++) {
+            sb.append("(" + fContexts[i].getLocation() + "," + fContexts[i].getRank() + ((i < fContexts.length - 1) ? ")," : ")]\n"));
+        }
+        sb.append("\tfEvents=[");
+        for (int i = 0; i < fEvents.length; i++) {
+            ITmfEvent event = fEvents[i];
+            sb.append(((event != null) ? fEvents[i].getTimestamp() : "(null)")  + ((i < fEvents.length - 1) ? "," : "]\n"));
+        }
+        sb.append("\tfLastTraceRead=" + fLastTraceRead + "\n");
+        sb.append("]");
+        return sb.toString();
+    }
+
 }
This page took 0.026026 seconds and 5 git commands to generate.