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