1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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
.linuxtools
.internal
.tmf
.core
.trace
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
22 * The experiment context in TMF.
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.
27 * This implies that the "next" event from each trace has already been
28 * read and that we at least know its timestamp.
30 * The last trace refers to the trace from which the last event was "consumed"
31 * at the experiment level.
33 public class TmfExperimentContext
extends TmfContext
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
40 * No last trace read indicator
42 public static final int NO_TRACE
= -1;
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 private ITmfContext
[] fContexts
;
49 private ITmfEvent
[] fEvents
;
50 private int fLastTraceRead
;
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
57 * Standard constructor
60 * The number of traces in the experiment
62 public TmfExperimentContext(final int nbTraces
) {
64 fContexts
= new ITmfContext
[nbTraces
];
65 fEvents
= new ITmfEvent
[nbTraces
];
66 fLastTraceRead
= NO_TRACE
;
70 public void dispose() {
71 for (ITmfContext context
: fContexts
) {
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
82 * Get the trace contexts composing this experiment context.
84 * @return The array of trace contexts
86 public ITmfContext
[] getContexts() {
91 * Get the trace events located at this experiment context's location.
93 * @return The array of trace events
95 public ITmfEvent
[] getEvents() {
100 * Get the index of the trace that was last read (so the trace whose
101 * current context will match this experiment's).
103 * @return The index of the trace
105 public int getLastTrace() {
106 return fLastTraceRead
;
110 * Set the last trace read index
113 * The new value to assign
115 public void setLastTrace(final int newIndex
) {
116 fLastTraceRead
= newIndex
;
119 // ------------------------------------------------------------------------
121 // ------------------------------------------------------------------------
124 public int hashCode() {
126 for (int i
= 0; i
< fContexts
.length
; i
++) {
127 result
= 37 * result
+ fContexts
[i
].hashCode();
133 public boolean equals(final Object other
) {
137 if (!super.equals(other
)) {
140 if (!(other
instanceof TmfExperimentContext
)) {
143 final TmfExperimentContext o
= (TmfExperimentContext
) other
;
144 boolean isEqual
= true;
146 while (isEqual
&& (i
< fContexts
.length
)) {
147 isEqual
&= fContexts
[i
].equals(o
.fContexts
[i
]);
154 @SuppressWarnings("nls")
155 public String
toString() {
156 StringBuilder sb
= new StringBuilder("TmfExperimentContext [\n");
157 sb
.append("\tfLocation=" + getLocation() + ", fRank=" + getRank() + "\n");
158 sb
.append("\tfContexts=[");
159 for (int i
= 0; i
< fContexts
.length
; i
++) {
160 sb
.append("(" + fContexts
[i
].getLocation() + "," + fContexts
[i
].getRank() + ((i
< fContexts
.length
- 1) ?
")," : ")]\n"));
162 sb
.append("\tfEvents=[");
163 for (int i
= 0; i
< fEvents
.length
; i
++) {
164 ITmfEvent event
= fEvents
[i
];
165 sb
.append(((event
!= null) ? fEvents
[i
].getTimestamp() : "(null)") + ((i
< fEvents
.length
- 1) ?
"," : "]\n"));
167 sb
.append("\tfLastTraceRead=" + fLastTraceRead
+ "\n");
169 return sb
.toString();
This page took 0.034782 seconds and 6 git commands to generate.