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