Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
ea271da6 | 2 | * Copyright (c) 2009, 2010, 2012, 2013 Ericsson |
ce2388e0 | 3 | * |
8c8bf09f ASL |
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 | |
ce2388e0 | 8 | * |
8c8bf09f ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
3bd44ac8 | 11 | * Francois Chouinard - Put in shape for 1.0 |
ea271da6 | 12 | * Patrick Tasse - Updated for removal of context clone |
8c8bf09f ASL |
13 | *******************************************************************************/ |
14 | ||
9e0640dc | 15 | package org.eclipse.linuxtools.internal.tmf.core.trace; |
8c8bf09f | 16 | |
72f1e62a | 17 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
34ccf9a9 | 18 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
6c13869b | 19 | import org.eclipse.linuxtools.tmf.core.trace.TmfContext; |
8c8bf09f ASL |
20 | |
21 | /** | |
0316808c | 22 | * The experiment context in TMF. |
8c8bf09f | 23 | * <p> |
cbdacf03 FC |
24 | * The experiment keeps track of the next event from each of its traces so it |
25 | * can pick the next one in chronological order. | |
8f50c396 | 26 | * <p> |
ce2388e0 | 27 | * This implies that the "next" event from each trace has already been |
ea271da6 | 28 | * read and that we at least know its timestamp. |
8f50c396 | 29 | * <p> |
cbdacf03 FC |
30 | * The last trace refers to the trace from which the last event was "consumed" |
31 | * at the experiment level. | |
8c8bf09f | 32 | */ |
9b749023 | 33 | public class TmfExperimentContext extends TmfContext { |
9f584e4c | 34 | |
cbdacf03 FC |
35 | // ------------------------------------------------------------------------ |
36 | // Constants | |
37 | // ------------------------------------------------------------------------ | |
38 | ||
0316808c FC |
39 | /** |
40 | * No last trace read indicator | |
41 | */ | |
9e0640dc | 42 | public static final int NO_TRACE = -1; |
cbdacf03 FC |
43 | |
44 | // ------------------------------------------------------------------------ | |
45 | // Attributes | |
46 | // ------------------------------------------------------------------------ | |
47 | ||
03648eab | 48 | private ITmfContext[] fContexts; |
ce2388e0 | 49 | private ITmfEvent[] fEvents; |
03648eab | 50 | private int fLastTraceRead; |
cbdacf03 FC |
51 | |
52 | // ------------------------------------------------------------------------ | |
53 | // Constructors | |
54 | // ------------------------------------------------------------------------ | |
55 | ||
408e65d2 | 56 | /** |
063f0d27 AM |
57 | * Standard constructor |
58 | * | |
ea271da6 PT |
59 | * @param nbTraces |
60 | * The number of traces in the experiment | |
408e65d2 | 61 | */ |
ea271da6 | 62 | public TmfExperimentContext(final int nbTraces) { |
cbdacf03 | 63 | super(); |
ea271da6 PT |
64 | fContexts = new ITmfContext[nbTraces]; |
65 | fEvents = new ITmfEvent[nbTraces]; | |
03648eab | 66 | fLastTraceRead = NO_TRACE; |
cbdacf03 FC |
67 | } |
68 | ||
4c9f2944 PT |
69 | /* (non-Javadoc) |
70 | * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext#dispose() | |
71 | */ | |
72 | @Override | |
73 | public void dispose() { | |
74 | for (ITmfContext context : fContexts) { | |
75 | context.dispose(); | |
76 | } | |
77 | super.dispose(); | |
78 | } | |
79 | ||
cbdacf03 FC |
80 | // ------------------------------------------------------------------------ |
81 | // Accessors | |
82 | // ------------------------------------------------------------------------ | |
83 | ||
063f0d27 AM |
84 | /** |
85 | * Get the trace contexts composing this experiment context. | |
86 | * | |
87 | * @return The array of trace contexts | |
88 | */ | |
cbdacf03 FC |
89 | public ITmfContext[] getContexts() { |
90 | return fContexts; | |
91 | } | |
92 | ||
063f0d27 AM |
93 | /** |
94 | * Get the trace events located at this experiment context's location. | |
95 | * | |
96 | * @return The array of trace events | |
97 | */ | |
cbdacf03 FC |
98 | public ITmfEvent[] getEvents() { |
99 | return fEvents; | |
100 | } | |
101 | ||
063f0d27 AM |
102 | /** |
103 | * Get the index of the trace that was last read (so the trace whose | |
104 | * current context will match this experiment's). | |
105 | * | |
106 | * @return The index of the trace | |
107 | */ | |
cbdacf03 | 108 | public int getLastTrace() { |
03648eab | 109 | return fLastTraceRead; |
cbdacf03 FC |
110 | } |
111 | ||
063f0d27 AM |
112 | /** |
113 | * Set the last trace read index | |
114 | * | |
115 | * @param newIndex | |
116 | * The new value to assign | |
117 | */ | |
cbdacf03 | 118 | public void setLastTrace(final int newIndex) { |
03648eab | 119 | fLastTraceRead = newIndex; |
cbdacf03 FC |
120 | } |
121 | ||
122 | // ------------------------------------------------------------------------ | |
123 | // Object | |
124 | // ------------------------------------------------------------------------ | |
550d787e FC |
125 | |
126 | @Override | |
127 | public int hashCode() { | |
cbdacf03 | 128 | int result = 17; |
0316808c | 129 | for (int i = 0; i < fContexts.length; i++) { |
cbdacf03 FC |
130 | result = 37 * result + fContexts[i].hashCode(); |
131 | } | |
132 | return result; | |
550d787e | 133 | } |
cbdacf03 | 134 | |
550d787e | 135 | @Override |
cbdacf03 | 136 | public boolean equals(final Object other) { |
9b749023 | 137 | if (this == other) { |
6e85c58d | 138 | return true; |
9b749023 AM |
139 | } |
140 | if (!super.equals(other)) { | |
6e85c58d | 141 | return false; |
9b749023 AM |
142 | } |
143 | if (!(other instanceof TmfExperimentContext)) { | |
cbdacf03 | 144 | return false; |
9b749023 | 145 | } |
cbdacf03 FC |
146 | final TmfExperimentContext o = (TmfExperimentContext) other; |
147 | boolean isEqual = true; | |
148 | int i = 0; | |
0316808c | 149 | while (isEqual && (i < fContexts.length)) { |
cbdacf03 FC |
150 | isEqual &= fContexts[i].equals(o.fContexts[i]); |
151 | i++; | |
152 | } | |
153 | return isEqual; | |
550d787e | 154 | } |
cbdacf03 | 155 | |
3bd44ac8 FC |
156 | @Override |
157 | @SuppressWarnings("nls") | |
158 | public String toString() { | |
159 | StringBuilder sb = new StringBuilder("TmfExperimentContext [\n"); | |
160 | sb.append("\tfLocation=" + getLocation() + ", fRank=" + getRank() + "\n"); | |
161 | sb.append("\tfContexts=["); | |
162 | for (int i = 0; i < fContexts.length; i++) { | |
163 | sb.append("(" + fContexts[i].getLocation() + "," + fContexts[i].getRank() + ((i < fContexts.length - 1) ? ")," : ")]\n")); | |
164 | } | |
165 | sb.append("\tfEvents=["); | |
166 | for (int i = 0; i < fEvents.length; i++) { | |
167 | ITmfEvent event = fEvents[i]; | |
168 | sb.append(((event != null) ? fEvents[i].getTimestamp() : "(null)") + ((i < fEvents.length - 1) ? "," : "]\n")); | |
169 | } | |
170 | sb.append("\tfLastTraceRead=" + fLastTraceRead + "\n"); | |
171 | sb.append("]"); | |
172 | return sb.toString(); | |
173 | } | |
174 | ||
8c8bf09f | 175 | } |