Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / trace / TmfContext.java
CommitLineData
8c8bf09f
ASL
1/*******************************************************************************
2 * Copyright (c) 2009, 2010 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 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.trace;
14
8c8bf09f
ASL
15/**
16 * <b><u>TmfContext</u></b>
17 * <p>
18 * Trace context structure. It ties a trace location to an event rank. The
19 * context should be enough to restore the trace state so the corresponding
20 * event can be read.
21 */
cbd4ad82 22public class TmfContext implements ITmfContext, Cloneable {
8c8bf09f 23
948b0607
FC
24 private ITmfLocation<? extends Comparable<?>> fLocation;
25 private long fRank;
26
27 // ------------------------------------------------------------------------
28 // Constructors
29 // ------------------------------------------------------------------------
30
31 public TmfContext(ITmfLocation<? extends Comparable<?>> loc, long rank) {
32 fLocation = loc;
33 fRank = rank;
34 }
35
36 public TmfContext(ITmfLocation<? extends Comparable<?>> location) {
37 this(location, UNKNOWN_RANK);
38 }
39
40 public TmfContext(TmfContext other) {
41 this(other.fLocation, other.fRank);
42 }
43
44 public TmfContext() {
45 this(null, UNKNOWN_RANK);
46 }
47
48 // ------------------------------------------------------------------------
49 // ITmfContext
50 // ------------------------------------------------------------------------
51
52 @Override
53 public void dispose() {
54 // override if necessary
55 }
56
57 @Override
58 public void setLocation(ITmfLocation<? extends Comparable<?>> location) {
59 fLocation = location;
60 }
61
62 @Override
63 public ITmfLocation<? extends Comparable<?>> getLocation() {
64 return fLocation;
65 }
66
67 @Override
68 public void setRank(long rank) {
69 fRank = rank;
70 }
71
72 @Override
73 public long getRank() {
74 return fRank;
75 }
76
77 @Override
78 public void updateRank(int delta) {
79 if (isValidRank())
80 fRank += delta;
81 }
82
83 @Override
84 public boolean isValidRank() {
85 return fRank != UNKNOWN_RANK;
86 }
87
88 // ------------------------------------------------------------------------
89 // Object
90 // ------------------------------------------------------------------------
ff4ed569
FC
91
92 @Override
93 public int hashCode() {
948b0607
FC
94 int result = 17;
95 result = 37 * result + fLocation.hashCode();
96 result = 37 * result + (int) (fRank ^ (fRank >>> 32));
97 return result;
ff4ed569 98 }
948b0607 99
ff4ed569
FC
100 @Override
101 public boolean equals(Object other) {
948b0607
FC
102 if (other == this) {
103 return true;
104 }
105 if (!(other instanceof TmfContext)) {
106 return false;
107 }
108 TmfContext o = (TmfContext) other;
109 return fLocation.equals(o.fLocation) && (fRank == o.fRank);
ff4ed569 110 }
948b0607
FC
111
112 @Override
3b38ea61 113 @SuppressWarnings("nls")
ff4ed569 114 public String toString() {
948b0607
FC
115 return "[TmfContext(" + fLocation.toString() + "," + fRank + ")]";
116 }
117
118 @Override
119 public TmfContext clone() {
120 TmfContext clone = null;
121 try {
122 clone = (TmfContext) super.clone();
123 clone.fLocation = fLocation.clone();
124 clone.fRank = fRank;
125 } catch (CloneNotSupportedException e) {
126 }
127 return clone;
ff4ed569 128 }
8c8bf09f
ASL
129
130}
This page took 0.035202 seconds and 5 git commands to generate.