Refactor TmfCheckpoint and dependencies
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfContext.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 Ericsson
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
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.trace;
15
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 */
23 public class TmfContext implements ITmfContext, Cloneable {
24
25 // ------------------------------------------------------------------------
26 // Attributes
27 // ------------------------------------------------------------------------
28
29 // The trace location
30 private ITmfLocation<? extends Comparable<?>> fLocation;
31
32 // The event rank
33 private long fRank;
34
35 // ------------------------------------------------------------------------
36 // Constructors
37 // ------------------------------------------------------------------------
38
39 /**
40 * Default constructor
41 */
42 public TmfContext() {
43 this(null, UNKNOWN_RANK);
44 }
45
46 /**
47 * Simple constructor (unknown rank)
48 *
49 * @param location the event location
50 */
51 public TmfContext(final ITmfLocation<? extends Comparable<?>> location) {
52 this(location, UNKNOWN_RANK);
53 }
54
55 /**
56 * Full constructor
57 *
58 * @param location the event location
59 * @param rank the event rank
60 */
61 public TmfContext(final ITmfLocation<? extends Comparable<?>> location, final long rank) {
62 fLocation = location;
63 fRank = rank;
64 }
65
66 /**
67 * Copy constructor
68 *
69 * @param context the other context
70 */
71 public TmfContext(final TmfContext context) {
72 if (context == null)
73 throw new IllegalArgumentException();
74 fLocation = context.fLocation;
75 fRank = context.fRank;
76 }
77
78 // ------------------------------------------------------------------------
79 // Cloneable
80 // ------------------------------------------------------------------------
81
82 /* (non-Javadoc)
83 * @see java.lang.Object#clone()
84 */
85 @Override
86 public TmfContext clone() {
87 TmfContext clone = null;
88 try {
89 clone = (TmfContext) super.clone();
90 clone.fLocation = (fLocation != null) ? fLocation.clone() : null;
91 clone.fRank = fRank;
92 } catch (final CloneNotSupportedException e) {
93 }
94 return clone;
95 }
96
97 // ------------------------------------------------------------------------
98 // ITmfContext
99 // ------------------------------------------------------------------------
100
101 /* (non-Javadoc)
102 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation()
103 */
104 @Override
105 public ITmfLocation<? extends Comparable<?>> getLocation() {
106 return fLocation;
107 }
108
109 /* (non-Javadoc)
110 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setLocation(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation)
111 */
112 @Override
113 public void setLocation(final ITmfLocation<? extends Comparable<?>> location) {
114 fLocation = location;
115 }
116
117 /* (non-Javadoc)
118 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank()
119 */
120 @Override
121 public long getRank() {
122 return fRank;
123 }
124
125 /* (non-Javadoc)
126 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long)
127 */
128 @Override
129 public void setRank(final long rank) {
130 fRank = rank;
131 }
132
133 /* (non-Javadoc)
134 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank()
135 */
136 @Override
137 public void increaseRank() {
138 if (hasValidRank())
139 fRank++;
140 }
141
142 /* (non-Javadoc)
143 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank()
144 */
145 @Override
146 public boolean hasValidRank() {
147 return fRank != UNKNOWN_RANK;
148 }
149
150 /* (non-Javadoc)
151 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose()
152 */
153 @Override
154 public void dispose() {
155 }
156
157 // ------------------------------------------------------------------------
158 // Object
159 // ------------------------------------------------------------------------
160
161 /* (non-Javadoc)
162 * @see java.lang.Object#hashCode()
163 */
164 @Override
165 public int hashCode() {
166 final int prime = 31;
167 int result = 1;
168 result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
169 result = prime * result + (int) (fRank ^ (fRank >>> 32));
170 return result;
171 }
172
173 /* (non-Javadoc)
174 * @see java.lang.Object#equals(java.lang.Object)
175 */
176 @Override
177 public boolean equals(final Object obj) {
178 if (this == obj)
179 return true;
180 if (obj == null)
181 return false;
182 if (getClass() != obj.getClass())
183 return false;
184 final TmfContext other = (TmfContext) obj;
185 if (fLocation == null) {
186 if (other.fLocation != null)
187 return false;
188 } else if (!fLocation.equals(other.fLocation))
189 return false;
190 if (fRank != other.fRank)
191 return false;
192 return true;
193 }
194
195 /* (non-Javadoc)
196 * @see java.lang.Object#toString()
197 */
198 @Override
199 @SuppressWarnings("nls")
200 public String toString() {
201 return "TmfContext [fLocation=" + fLocation + ", fRank=" + fRank + "]";
202 }
203
204 }
This page took 0.034272 seconds and 5 git commands to generate.