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(final ITmfLocation
<?
extends Comparable
<?
>> location
) {
52 this(location
, UNKNOWN_RANK
);
58 * @param location the event location
59 * @param rank the event rank
61 public TmfContext(final ITmfLocation
<?
extends Comparable
<?
>> location
, final long rank
) {
69 * @param context the other context
71 public TmfContext(final TmfContext context
) {
73 throw new IllegalArgumentException();
74 fLocation
= context
.fLocation
;
75 fRank
= context
.fRank
;
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
83 * @see java.lang.Object#clone()
86 public TmfContext
clone() {
87 TmfContext clone
= null;
89 clone
= (TmfContext
) super.clone();
90 clone
.fLocation
= (fLocation
!= null) ? fLocation
.clone() : null;
92 } catch (final CloneNotSupportedException e
) {
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
102 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation()
105 public ITmfLocation
<?
extends Comparable
<?
>> getLocation() {
110 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setLocation(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation)
113 public void setLocation(final ITmfLocation
<?
extends Comparable
<?
>> location
) {
114 fLocation
= location
;
118 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank()
121 public long getRank() {
126 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long)
129 public void setRank(final long rank
) {
134 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank()
137 public void increaseRank() {
143 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank()
146 public boolean hasValidRank() {
147 return fRank
!= UNKNOWN_RANK
;
151 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose()
154 public void dispose() {
157 // ------------------------------------------------------------------------
159 // ------------------------------------------------------------------------
162 * @see java.lang.Object#hashCode()
165 public int hashCode() {
166 final int prime
= 31;
168 result
= prime
* result
+ ((fLocation
== null) ?
0 : fLocation
.hashCode());
169 result
= prime
* result
+ (int) (fRank ^
(fRank
>>> 32));
174 * @see java.lang.Object#equals(java.lang.Object)
177 public boolean equals(final Object obj
) {
182 if (getClass() != obj
.getClass())
184 final TmfContext other
= (TmfContext
) obj
;
185 if (fLocation
== null) {
186 if (other
.fLocation
!= null)
188 } else if (!fLocation
.equals(other
.fLocation
))
190 if (fRank
!= other
.fRank
)
196 * @see java.lang.Object#toString()
199 @SuppressWarnings("nls")
200 public String
toString() {
201 return "TmfContext [fLocation=" + fLocation
+ ", fRank=" + fRank
+ "]";