Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
cbdacf03 | 2 | * Copyright (c) 2009, 2010, 2012 Ericsson |
1e1bef82 | 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 | |
1e1bef82 | 8 | * |
8c8bf09f ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
cbdacf03 | 11 | * Francois Chouinard - Updated as per TMF Trace Model 1.0 |
8c8bf09f ASL |
12 | *******************************************************************************/ |
13 | ||
6c13869b | 14 | package org.eclipse.linuxtools.tmf.core.trace; |
8c8bf09f | 15 | |
8c8bf09f | 16 | /** |
2848c377 FC |
17 | * A basic implementation of ITmfContext. |
18 | * <p> | |
19 | * It ties a trace location to an event rank. The context should be enough to | |
20 | * restore the trace state so the corresponding event can be read. | |
1e1bef82 | 21 | * |
f7703ed6 FC |
22 | * @version 1.0 |
23 | * @author Francois Chouinard | |
24 | * | |
f7703ed6 | 25 | * @see ITmfLocation |
8c8bf09f | 26 | */ |
cbd4ad82 | 27 | public class TmfContext implements ITmfContext, Cloneable { |
8c8bf09f | 28 | |
cbdacf03 FC |
29 | // ------------------------------------------------------------------------ |
30 | // Attributes | |
31 | // ------------------------------------------------------------------------ | |
32 | ||
33 | // The trace location | |
1e1bef82 | 34 | private ITmfLocation fLocation; |
cbdacf03 FC |
35 | |
36 | // The event rank | |
948b0607 FC |
37 | private long fRank; |
38 | ||
39 | // ------------------------------------------------------------------------ | |
40 | // Constructors | |
41 | // ------------------------------------------------------------------------ | |
42 | ||
cbdacf03 FC |
43 | /** |
44 | * Default constructor | |
45 | */ | |
46 | public TmfContext() { | |
47 | this(null, UNKNOWN_RANK); | |
948b0607 FC |
48 | } |
49 | ||
cbdacf03 FC |
50 | /** |
51 | * Simple constructor (unknown rank) | |
1e1bef82 | 52 | * |
cbdacf03 FC |
53 | * @param location the event location |
54 | */ | |
1e1bef82 | 55 | public TmfContext(final ITmfLocation location) { |
948b0607 FC |
56 | this(location, UNKNOWN_RANK); |
57 | } | |
58 | ||
cbdacf03 FC |
59 | /** |
60 | * Full constructor | |
1e1bef82 | 61 | * |
cbdacf03 FC |
62 | * @param location the event location |
63 | * @param rank the event rank | |
64 | */ | |
1e1bef82 | 65 | public TmfContext(final ITmfLocation location, final long rank) { |
cbdacf03 FC |
66 | fLocation = location; |
67 | fRank = rank; | |
948b0607 FC |
68 | } |
69 | ||
cbdacf03 FC |
70 | /** |
71 | * Copy constructor | |
1e1bef82 | 72 | * |
cbdacf03 FC |
73 | * @param context the other context |
74 | */ | |
5d837f9b | 75 | public TmfContext(final TmfContext context) { |
0316808c | 76 | if (context == null) { |
5d837f9b | 77 | throw new IllegalArgumentException(); |
0316808c | 78 | } |
5d837f9b FC |
79 | fLocation = context.fLocation; |
80 | fRank = context.fRank; | |
cbdacf03 FC |
81 | } |
82 | ||
83 | // ------------------------------------------------------------------------ | |
84 | // Cloneable | |
85 | // ------------------------------------------------------------------------ | |
86 | ||
87 | /* (non-Javadoc) | |
88 | * @see java.lang.Object#clone() | |
89 | */ | |
90 | @Override | |
91 | public TmfContext clone() { | |
92 | TmfContext clone = null; | |
93 | try { | |
94 | clone = (TmfContext) super.clone(); | |
5d837f9b | 95 | clone.fLocation = (fLocation != null) ? fLocation.clone() : null; |
cbdacf03 | 96 | clone.fRank = fRank; |
5d837f9b | 97 | } catch (final CloneNotSupportedException e) { |
cbdacf03 FC |
98 | } |
99 | return clone; | |
948b0607 FC |
100 | } |
101 | ||
102 | // ------------------------------------------------------------------------ | |
103 | // ITmfContext | |
104 | // ------------------------------------------------------------------------ | |
105 | ||
cbdacf03 FC |
106 | /* (non-Javadoc) |
107 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation() | |
108 | */ | |
948b0607 | 109 | @Override |
1e1bef82 | 110 | public ITmfLocation getLocation() { |
cbdacf03 | 111 | return fLocation; |
948b0607 FC |
112 | } |
113 | ||
cbdacf03 FC |
114 | /* (non-Javadoc) |
115 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setLocation(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation) | |
116 | */ | |
948b0607 | 117 | @Override |
1e1bef82 | 118 | public void setLocation(final ITmfLocation location) { |
948b0607 FC |
119 | fLocation = location; |
120 | } | |
121 | ||
cbdacf03 FC |
122 | /* (non-Javadoc) |
123 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank() | |
124 | */ | |
948b0607 | 125 | @Override |
cbdacf03 FC |
126 | public long getRank() { |
127 | return fRank; | |
948b0607 FC |
128 | } |
129 | ||
cbdacf03 FC |
130 | /* (non-Javadoc) |
131 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long) | |
132 | */ | |
948b0607 | 133 | @Override |
5d837f9b | 134 | public void setRank(final long rank) { |
948b0607 FC |
135 | fRank = rank; |
136 | } | |
137 | ||
cbdacf03 FC |
138 | /* (non-Javadoc) |
139 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank() | |
140 | */ | |
948b0607 | 141 | @Override |
cbdacf03 | 142 | public void increaseRank() { |
0316808c | 143 | if (hasValidRank()) { |
cbdacf03 | 144 | fRank++; |
0316808c | 145 | } |
948b0607 FC |
146 | } |
147 | ||
cbdacf03 FC |
148 | /* (non-Javadoc) |
149 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank() | |
150 | */ | |
948b0607 | 151 | @Override |
cbdacf03 FC |
152 | public boolean hasValidRank() { |
153 | return fRank != UNKNOWN_RANK; | |
948b0607 FC |
154 | } |
155 | ||
cbdacf03 FC |
156 | /* (non-Javadoc) |
157 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose() | |
158 | */ | |
948b0607 | 159 | @Override |
cbdacf03 | 160 | public void dispose() { |
948b0607 FC |
161 | } |
162 | ||
163 | // ------------------------------------------------------------------------ | |
164 | // Object | |
165 | // ------------------------------------------------------------------------ | |
ff4ed569 | 166 | |
cbdacf03 FC |
167 | /* (non-Javadoc) |
168 | * @see java.lang.Object#hashCode() | |
169 | */ | |
ff4ed569 FC |
170 | @Override |
171 | public int hashCode() { | |
cbdacf03 FC |
172 | final int prime = 31; |
173 | int result = 1; | |
174 | result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode()); | |
175 | result = prime * result + (int) (fRank ^ (fRank >>> 32)); | |
948b0607 | 176 | return result; |
ff4ed569 | 177 | } |
948b0607 | 178 | |
cbdacf03 FC |
179 | /* (non-Javadoc) |
180 | * @see java.lang.Object#equals(java.lang.Object) | |
181 | */ | |
ff4ed569 | 182 | @Override |
5d837f9b | 183 | public boolean equals(final Object obj) { |
0316808c | 184 | if (this == obj) { |
948b0607 | 185 | return true; |
0316808c FC |
186 | } |
187 | if (obj == null) { | |
948b0607 | 188 | return false; |
0316808c FC |
189 | } |
190 | if (getClass() != obj.getClass()) { | |
cbdacf03 | 191 | return false; |
0316808c | 192 | } |
5d837f9b | 193 | final TmfContext other = (TmfContext) obj; |
cbdacf03 | 194 | if (fLocation == null) { |
0316808c | 195 | if (other.fLocation != null) { |
cbdacf03 | 196 | return false; |
0316808c FC |
197 | } |
198 | } else if (!fLocation.equals(other.fLocation)) { | |
cbdacf03 | 199 | return false; |
0316808c FC |
200 | } |
201 | if (fRank != other.fRank) { | |
cbdacf03 | 202 | return false; |
0316808c | 203 | } |
cbdacf03 | 204 | return true; |
ff4ed569 | 205 | } |
948b0607 | 206 | |
cbdacf03 FC |
207 | /* (non-Javadoc) |
208 | * @see java.lang.Object#toString() | |
209 | */ | |
948b0607 | 210 | @Override |
3b38ea61 | 211 | @SuppressWarnings("nls") |
ff4ed569 | 212 | public String toString() { |
cbdacf03 | 213 | return "TmfContext [fLocation=" + fLocation + ", fRank=" + fRank + "]"; |
ff4ed569 | 214 | } |
8c8bf09f ASL |
215 | |
216 | } |