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 * <b><u>TmfContext</u></b>
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
23 public class TmfContext
implements ITmfContext
, Cloneable
{
25 // ------------------------------------------------------------------------
27 // ------------------------------------------------------------------------
30 private ITmfLocation
<?
extends Comparable
<?
>> fLocation
;
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
43 this(null, UNKNOWN_RANK
);
47 * Simple constructor (unknown rank)
49 * @param location the event location
51 public TmfContext(ITmfLocation
<?
extends Comparable
<?
>> location
) {
52 this(location
, UNKNOWN_RANK
);
58 * @param location the event location
59 * @param rank the event rank
61 public TmfContext(ITmfLocation
<?
extends Comparable
<?
>> location
, long rank
) {
69 * @param context the other context
71 public TmfContext(TmfContext context
) {
72 this(context
.fLocation
, context
.fRank
);
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
80 * @see java.lang.Object#clone()
83 public TmfContext
clone() {
84 TmfContext clone
= null;
86 clone
= (TmfContext
) super.clone();
87 clone
.fLocation
= fLocation
.clone();
89 } catch (CloneNotSupportedException e
) {
94 // ------------------------------------------------------------------------
96 // ------------------------------------------------------------------------
99 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation()
102 public ITmfLocation
<?
extends Comparable
<?
>> getLocation() {
107 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setLocation(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation)
110 public void setLocation(ITmfLocation
<?
extends Comparable
<?
>> location
) {
111 fLocation
= location
;
115 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank()
118 public long getRank() {
123 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long)
126 public void setRank(long rank
) {
131 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank()
134 public void increaseRank() {
140 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank()
143 public boolean hasValidRank() {
144 return fRank
!= UNKNOWN_RANK
;
148 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose()
151 public void dispose() {
154 // ------------------------------------------------------------------------
156 // ------------------------------------------------------------------------
159 * @see java.lang.Object#hashCode()
162 public int hashCode() {
163 final int prime
= 31;
165 result
= prime
* result
+ ((fLocation
== null) ?
0 : fLocation
.hashCode());
166 result
= prime
* result
+ (int) (fRank ^
(fRank
>>> 32));
171 * @see java.lang.Object#equals(java.lang.Object)
174 public boolean equals(Object obj
) {
179 if (getClass() != obj
.getClass())
181 TmfContext other
= (TmfContext
) obj
;
182 if (fLocation
== null) {
183 if (other
.fLocation
!= null)
185 } else if (!fLocation
.equals(other
.fLocation
))
187 if (fRank
!= other
.fRank
)
193 * @see java.lang.Object#toString()
196 @SuppressWarnings("nls")
197 public String
toString() {
198 return "TmfContext [fLocation=" + fLocation
+ ", fRank=" + fRank
+ "]";