Commit | Line | Data |
---|---|---|
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 | ||
13 | package 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 | */ | |
cbd4ad82 | 23 | public class TmfContext implements ITmfContext, Cloneable { |
8c8bf09f | 24 | |
a79913eb | 25 | private ITmfLocation<? extends Comparable<?>> fLocation; |
8c8bf09f ASL |
26 | private long fRank; |
27 | ||
28 | // ------------------------------------------------------------------------ | |
29 | // Constructors | |
30 | // ------------------------------------------------------------------------ | |
31 | ||
a79913eb | 32 | public TmfContext(ITmfLocation<? extends Comparable<?>> loc, long rank) { |
8c8bf09f ASL |
33 | fLocation = loc; |
34 | fRank = rank; | |
35 | } | |
36 | ||
a79913eb | 37 | public TmfContext(ITmfLocation<? extends Comparable<?>> location) { |
550d787e | 38 | this(location, UNKNOWN_RANK); |
8c8bf09f ASL |
39 | } |
40 | ||
41 | public TmfContext(TmfContext other) { | |
42 | this(other.fLocation, other.fRank); | |
43 | } | |
44 | ||
fc6ccf6f | 45 | public TmfContext() { |
550d787e | 46 | this(null, UNKNOWN_RANK); |
9f584e4c FC |
47 | } |
48 | ||
8c8bf09f ASL |
49 | // ------------------------------------------------------------------------ |
50 | // ITmfContext | |
51 | // ------------------------------------------------------------------------ | |
52 | ||
d4011df2 | 53 | @Override |
a79913eb | 54 | public void setLocation(ITmfLocation<? extends Comparable<?>> location) { |
452ad365 | 55 | fLocation = location; |
8c8bf09f ASL |
56 | } |
57 | ||
d4011df2 | 58 | @Override |
a79913eb | 59 | public ITmfLocation<? extends Comparable<?>> getLocation() { |
8c8bf09f ASL |
60 | return fLocation; |
61 | } | |
62 | ||
d4011df2 | 63 | @Override |
452ad365 FC |
64 | public void setRank(long rank) { |
65 | fRank = rank; | |
8c8bf09f ASL |
66 | } |
67 | ||
d4011df2 | 68 | @Override |
8c8bf09f ASL |
69 | public long getRank() { |
70 | return fRank; | |
71 | } | |
72 | ||
d4011df2 | 73 | @Override |
452ad365 | 74 | public void updateRank(int delta) { |
550d787e | 75 | if (isValidRank()) |
ff4ed569 FC |
76 | fRank += delta; |
77 | } | |
78 | ||
d4011df2 | 79 | @Override |
550d787e FC |
80 | public boolean isValidRank() { |
81 | return fRank != UNKNOWN_RANK; | |
82 | } | |
83 | ||
ff4ed569 FC |
84 | // ------------------------------------------------------------------------ |
85 | // Object | |
86 | // ------------------------------------------------------------------------ | |
87 | ||
88 | @Override | |
89 | public int hashCode() { | |
90 | int result = 17; | |
91 | result = 37 * result + fLocation.hashCode(); | |
92 | result = 37 * result + (int) (fRank ^ (fRank >>> 32)); | |
93 | return result; | |
94 | } | |
95 | ||
96 | @Override | |
97 | public boolean equals(Object other) { | |
f6b14ce2 FC |
98 | if (other == this) { |
99 | return true; | |
100 | } | |
ff4ed569 FC |
101 | if (!(other instanceof TmfContext)) { |
102 | return false; | |
103 | } | |
104 | TmfContext o = (TmfContext) other; | |
105 | return fLocation.equals(o.fLocation) && (fRank == o.fRank); | |
106 | } | |
107 | ||
3b38ea61 FC |
108 | @Override |
109 | @SuppressWarnings("nls") | |
ff4ed569 FC |
110 | public String toString() { |
111 | return "[TmfContext(" + fLocation.toString() + "," + fRank + ")]"; | |
112 | } | |
113 | ||
114 | @Override | |
115 | public TmfContext clone() { | |
116 | TmfContext clone = null; | |
117 | try { | |
118 | clone = (TmfContext) super.clone(); | |
119 | clone.fLocation = fLocation.clone(); | |
120 | clone.fRank = fRank; | |
121 | } catch (CloneNotSupportedException e) { | |
122 | } | |
123 | return clone; | |
8c8bf09f ASL |
124 | } |
125 | ||
126 | } |