*
* 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;
* 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
// ------------------------------------------------------------------------
/**
+ * 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);
}
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;
}
// 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;
}
@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;
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();
+ }
+
}