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