1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.trace
;
17 * A basic implementation of ITmfContext.
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.
23 * @author Francois Chouinard
27 public class TmfContext
implements ITmfContext
, Cloneable
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
34 private ITmfLocation fLocation
;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
47 this(null, UNKNOWN_RANK
);
51 * Simple constructor (unknown rank)
53 * @param location the event location
55 public TmfContext(final ITmfLocation location
) {
56 this(location
, UNKNOWN_RANK
);
62 * @param location the event location
63 * @param rank the event rank
65 public TmfContext(final ITmfLocation location
, final long rank
) {
73 * @param context the other context
75 public TmfContext(final TmfContext context
) {
76 if (context
== null) {
77 throw new IllegalArgumentException();
79 fLocation
= context
.fLocation
;
80 fRank
= context
.fRank
;
83 // ------------------------------------------------------------------------
85 // ------------------------------------------------------------------------
88 * @see java.lang.Object#clone()
91 public TmfContext
clone() {
92 TmfContext clone
= null;
94 clone
= (TmfContext
) super.clone();
95 clone
.fLocation
= (fLocation
!= null) ? fLocation
.clone() : null;
97 } catch (final CloneNotSupportedException e
) {
102 // ------------------------------------------------------------------------
104 // ------------------------------------------------------------------------
107 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation()
110 public ITmfLocation
getLocation() {
115 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setLocation(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation)
118 public void setLocation(final ITmfLocation location
) {
119 fLocation
= location
;
123 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank()
126 public long getRank() {
131 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long)
134 public void setRank(final long rank
) {
139 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank()
142 public void increaseRank() {
143 if (hasValidRank()) {
149 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank()
152 public boolean hasValidRank() {
153 return fRank
!= UNKNOWN_RANK
;
157 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose()
160 public void dispose() {
163 // ------------------------------------------------------------------------
165 // ------------------------------------------------------------------------
168 * @see java.lang.Object#hashCode()
171 public int hashCode() {
172 final int prime
= 31;
174 result
= prime
* result
+ ((fLocation
== null) ?
0 : fLocation
.hashCode());
175 result
= prime
* result
+ (int) (fRank ^
(fRank
>>> 32));
180 * @see java.lang.Object#equals(java.lang.Object)
183 public boolean equals(final Object obj
) {
190 if (getClass() != obj
.getClass()) {
193 final TmfContext other
= (TmfContext
) obj
;
194 if (fLocation
== null) {
195 if (other
.fLocation
!= null) {
198 } else if (!fLocation
.equals(other
.fLocation
)) {
201 if (fRank
!= other
.fRank
) {
208 * @see java.lang.Object#toString()
211 @SuppressWarnings("nls")
212 public String
toString() {
213 return "TmfContext [fLocation=" + fLocation
+ ", fRank=" + fRank
+ "]";