Change ITmfTrace<T extends TmfEvent> to ITmfTrace<T extends ITmfEvent>
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / experiment / TmfExperimentContext.java
CommitLineData
8c8bf09f
ASL
1/*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
6c13869b 13package org.eclipse.linuxtools.tmf.core.experiment;
8c8bf09f 14
72f1e62a 15import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
6c13869b
FC
16import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
17import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
18import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
8c8bf09f
ASL
19
20/**
21 * <b><u>TmfExperimentContext</u></b>
22 * <p>
8f50c396
FC
23 * The experiment keeps track of the next event from each of its traces so
24 * it can pick the next one in chronological order.
25 * <p>
26 * This implies that the "next" event from each trace has already been
27 * read and that we at least know its timestamp. This doesn't imply that a
28 * full parse of the event content was performed (read: LTTng works like
29 * this).
30 * <p>
31 * The last trace refers to the trace from which the last event was
32 * "consumed" at the experiment level.
8c8bf09f 33 */
9f584e4c
FC
34public class TmfExperimentContext extends TmfContext {
35
8f50c396
FC
36 // ------------------------------------------------------------------------
37 // Constants
38 // ------------------------------------------------------------------------
39
40 public static final int NO_TRACE = -1;
41
42 // ------------------------------------------------------------------------
43 // Attributes
44 // ------------------------------------------------------------------------
45
4df4581d 46 private ITmfTrace<?>[] fTraces = new ITmfTrace[0];
9f584e4c 47 private TmfContext[] fContexts;
72f1e62a 48 private ITmfEvent[] fEvents;
9b635e61 49 private int lastTraceRead;
8c8bf09f 50
9f584e4c
FC
51 // ------------------------------------------------------------------------
52 // Constructors
53 // ------------------------------------------------------------------------
8c8bf09f 54
4df4581d 55 public TmfExperimentContext(ITmfTrace<?>[] traces, TmfContext[] contexts) {
9f584e4c
FC
56 super();
57 fTraces = traces;
58 fContexts = contexts;
72f1e62a 59 fEvents = new ITmfEvent[fTraces.length];
8c8bf09f 60
452ad365 61 ITmfLocation<?>[] locations = new ITmfLocation[fTraces.length];
8f50c396 62 long[] ranks = new long[fTraces.length];
9f584e4c
FC
63 long rank = 0;
64 for (int i = 0; i < fTraces.length; i++) {
65 if (contexts[i] != null) {
66 locations[i] = contexts[i].getLocation();
8f50c396 67 ranks[i] = contexts[i].getRank();
9f584e4c
FC
68 rank += contexts[i].getRank();
69 }
8c8bf09f 70 }
9f584e4c 71
a79913eb 72 setLocation(new TmfExperimentLocation(new TmfLocationArray(locations), ranks));
9f584e4c 73 setRank(rank);
9b635e61 74 lastTraceRead = NO_TRACE;
8c8bf09f
ASL
75 }
76
4df4581d 77 public TmfExperimentContext(ITmfTrace<?>[] traces) {
9f584e4c 78 this(traces, new TmfContext[traces.length]);
8c8bf09f
ASL
79 }
80
9f584e4c
FC
81 public TmfExperimentContext(TmfExperimentContext other) {
82 this(other.fTraces, other.cloneContexts());
83 fEvents = other.fEvents;
9b635e61
FC
84 if (other.getLocation() != null)
85 setLocation(other.getLocation().clone());
9f584e4c 86 setRank(other.getRank());
9b635e61 87 setLastTrace(other.lastTraceRead);
8c8bf09f
ASL
88 }
89
9f584e4c
FC
90 private TmfContext[] cloneContexts() {
91 TmfContext[] contexts = new TmfContext[fContexts.length];
8c8bf09f
ASL
92 for (int i = 0; i < fContexts.length; i++)
93 contexts[i] = fContexts[i].clone();
94 return contexts;
95 }
96
9f584e4c
FC
97 // ------------------------------------------------------------------------
98 // Accessors
99 // ------------------------------------------------------------------------
100
4df4581d 101 public ITmfTrace<?>[] getTraces() {
9f584e4c
FC
102 return fTraces;
103 }
104
105 public TmfContext[] getContexts() {
106 return fContexts;
107 }
108
72f1e62a 109 public ITmfEvent[] getEvents() {
8c8bf09f
ASL
110 return fEvents;
111 }
112
7f407ead 113 public int getLastTrace() {
9b635e61 114 return lastTraceRead;
7f407ead
FC
115 }
116
117 public void setLastTrace(int newIndex) {
9b635e61 118 lastTraceRead = newIndex;
7f407ead
FC
119 }
120
550d787e
FC
121 // ------------------------------------------------------------------------
122 // Object
123 // ------------------------------------------------------------------------
124
125 @Override
126 public int hashCode() {
127 int result = 17;
128 for (int i = 0; i < fTraces.length; i++) {
129 result = 37 * result + fTraces[i].hashCode();
130 result = 37 * result + fContexts[i].hashCode();
131 }
132 return result;
133 }
134
135 @Override
136 public boolean equals(Object other) {
6e85c58d
FC
137 if (this == other)
138 return true;
139 if (!super.equals(other))
140 return false;
550d787e
FC
141 if (!(other instanceof TmfExperimentContext)) {
142 return false;
143 }
144 TmfExperimentContext o = (TmfExperimentContext) other;
145 boolean isEqual = true;
146 int i = 0;
147 while (isEqual && i < fTraces.length) {
148 isEqual &= fTraces[i].equals(o.fTraces[i]);
149 isEqual &= fContexts[i].equals(o.fContexts[i]);
9b635e61 150 i++;
550d787e
FC
151 }
152 return isEqual;
153 }
154
8c8bf09f 155}
This page took 0.038665 seconds and 5 git commands to generate.