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