1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Put in shape for 1.0
12 * Patrick Tasse - Updated for removal of context clone
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.internal
.tmf
.core
.trace
.experiment
;
17 import java
.util
.ArrayList
;
18 import java
.util
.List
;
20 import org
.eclipse
.jdt
.annotation
.Nullable
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfContext
;
26 * The experiment context in TMF.
28 * The experiment keeps track of the next event from each of its traces so it
29 * can pick the next one in chronological order.
31 * This implies that the "next" event from each trace has already been
32 * read and that we at least know its timestamp.
34 * The last trace refers to the trace from which the last event was "consumed"
35 * at the experiment level.
37 public final class TmfExperimentContext
extends TmfContext
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 * No last trace read indicator
46 public static final int NO_TRACE
= -1;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 private final List
<ITmfContext
> fContexts
;
53 private final List
<ITmfEvent
> fEvents
;
54 private int fLastTraceRead
;
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 * Standard constructor
64 * The number of traces in the experiment
66 public TmfExperimentContext(final int nbTraces
) {
68 fLastTraceRead
= NO_TRACE
;
69 fContexts
= new ArrayList
<>(nbTraces
);
70 fEvents
= new ArrayList
<>(nbTraces
);
73 /* Initialize the arrays to the requested size */
74 for (int i
= 0; i
< nbTraces
; i
++) {
81 public void dispose() {
82 for (ITmfContext context
: fContexts
) {
88 // ------------------------------------------------------------------------
90 // ------------------------------------------------------------------------
93 * Return how many traces this experiment context tracks the contexts of
94 * (a.k.a., the number of traces in the experiment).
96 * @return The number of traces in the experiment
98 public int getNbTraces() {
99 return fContexts
.size();
103 * Get the current context of a specific trace
106 * The index of the trace in the experiment
107 * @return The matching context object for that trace
110 public ITmfContext
getContext(int traceIndex
) {
111 return fContexts
.get(traceIndex
);
115 * Set the context of a trace
118 * The index of the trace in the experiment
120 * The new context object for that trace
122 public void setContext(int traceIndex
, ITmfContext ctx
) {
123 fContexts
.set(traceIndex
, ctx
);
127 * Get the current event for a specific trace in the experiment.
130 * The index of the trace in the experiment
131 * @return The event matching the trace/context
135 public ITmfEvent
getEvent(int traceIndex
) {
136 return fEvents
.get(traceIndex
);
140 * Set the context's event for a specific trace
143 * The index of the trace in the experiment
145 * The event at the context in the trace
147 public void setEvent(int traceIndex
, ITmfEvent event
) {
148 fEvents
.set(traceIndex
, event
);
152 * Get the index of the trace that was last read (so the trace whose
153 * current context will match this experiment's).
155 * @return The index of the trace
157 public int getLastTrace() {
158 return fLastTraceRead
;
162 * Set the last trace read index
165 * The new value to assign
167 public void setLastTrace(final int newIndex
) {
168 fLastTraceRead
= newIndex
;
171 // ------------------------------------------------------------------------
173 // ------------------------------------------------------------------------
176 public int hashCode() {
178 for (int i
= 0; i
< fContexts
.size(); i
++) {
179 result
= 37 * result
+ fContexts
.get(i
).hashCode();
185 public boolean equals(final Object other
) {
189 if (!super.equals(other
)) {
192 if (!(other
instanceof TmfExperimentContext
)) {
195 final TmfExperimentContext o
= (TmfExperimentContext
) other
;
196 boolean isEqual
= true;
198 while (isEqual
&& (i
< fContexts
.size())) {
199 isEqual
&= fContexts
.get(i
).equals(o
.fContexts
.get(i
));
206 @SuppressWarnings("nls")
207 public String
toString() {
208 StringBuilder sb
= new StringBuilder("TmfExperimentContext [\n");
209 sb
.append("\tfLocation=" + getLocation() + ", fRank=" + getRank() + "\n");
210 sb
.append("\tfContexts=[");
211 for (int i
= 0; i
< fContexts
.size(); i
++) {
212 sb
.append("(" + fContexts
.get(i
).getLocation() + "," + fContexts
.get(i
).getRank() + ((i
< fContexts
.size() - 1) ?
")," : ")]\n"));
214 sb
.append("\tfEvents=[");
215 for (int i
= 0; i
< fEvents
.size(); i
++) {
216 ITmfEvent event
= fEvents
.get(i
);
217 sb
.append(((event
!= null) ? fEvents
.get(i
).getTimestamp() : "(null)") + ((i
< fEvents
.size() - 1) ?
"," : "]\n"));
219 sb
.append("\tfLastTraceRead=" + fLastTraceRead
+ "\n");
221 return sb
.toString();
This page took 0.035466 seconds and 5 git commands to generate.