(no commit message)
[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
15
16/**
17 * <b><u>TmfContext</u></b>
18 * <p>
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
21 * event can be read.
22 */
23public class TmfContext implements ITmfContext, Cloneable {
24
25 private ITmfLocation<?> fLocation;
26 private long fRank;
27
28 // ------------------------------------------------------------------------
29 // Constructors
30 // ------------------------------------------------------------------------
31
32 public TmfContext(ITmfLocation<?> loc, long rank) {
33 fLocation = loc;
34 fRank = rank;
35 }
36
37 public TmfContext(ITmfLocation<?> location) {
38 this(location, 0);
39 }
40
41 public TmfContext(TmfContext other) {
42 this(other.fLocation, other.fRank);
43 }
44
45 public TmfContext() {
46 this(null, 0);
47 }
48
49 // ------------------------------------------------------------------------
50 // ITmfContext
51 // ------------------------------------------------------------------------
52
53 public void setLocation(ITmfLocation<?> location) {
54 fLocation = location;
55 }
56
57 public ITmfLocation<?> getLocation() {
58 return fLocation;
59 }
60
61 public void setRank(long rank) {
62 fRank = rank;
63 }
64
65 public long getRank() {
66 return fRank;
67 }
68
69 public void updateRank(int delta) {
70 if (fRank != UNKNOWN_RANK)
71 fRank += delta;
72 }
73
74 // ------------------------------------------------------------------------
75 // Object
76 // ------------------------------------------------------------------------
77
78 @Override
79 public int hashCode() {
80 int result = 17;
81 result = 37 * result + fLocation.hashCode();
82 result = 37 * result + (int) (fRank ^ (fRank >>> 32));
83 return result;
84 }
85
86 @Override
87 public boolean equals(Object other) {
88 if (!(other instanceof TmfContext)) {
89 return false;
90 }
91 TmfContext o = (TmfContext) other;
92 return fLocation.equals(o.fLocation) && (fRank == o.fRank);
93 }
94
95 @Override
96 public String toString() {
97 return "[TmfContext(" + fLocation.toString() + "," + fRank + ")]";
98 }
99
100 @Override
101 public TmfContext clone() {
102 TmfContext clone = null;
103 try {
104 clone = (TmfContext) super.clone();
105 clone.fLocation = fLocation.clone();
106 clone.fRank = fRank;
107 } catch (CloneNotSupportedException e) {
108 }
109 return clone;
110 }
111
112}
This page took 0.028674 seconds and 5 git commands to generate.