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 | |
452ad365 | 25 | private ITmfLocation<?> fLocation; |
8c8bf09f ASL |
26 | private long fRank; |
27 | ||
28 | // ------------------------------------------------------------------------ | |
29 | // Constructors | |
30 | // ------------------------------------------------------------------------ | |
31 | ||
452ad365 | 32 | public TmfContext(ITmfLocation<?> loc, long rank) { |
8c8bf09f ASL |
33 | fLocation = loc; |
34 | fRank = rank; | |
35 | } | |
36 | ||
452ad365 | 37 | public TmfContext(ITmfLocation<?> 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 | ||
452ad365 FC |
53 | public void setLocation(ITmfLocation<?> location) { |
54 | fLocation = location; | |
8c8bf09f ASL |
55 | } |
56 | ||
452ad365 | 57 | public ITmfLocation<?> getLocation() { |
8c8bf09f ASL |
58 | return fLocation; |
59 | } | |
60 | ||
452ad365 FC |
61 | public void setRank(long rank) { |
62 | fRank = rank; | |
8c8bf09f ASL |
63 | } |
64 | ||
65 | public long getRank() { | |
66 | return fRank; | |
67 | } | |
68 | ||
452ad365 | 69 | public void updateRank(int delta) { |
550d787e | 70 | if (isValidRank()) |
ff4ed569 FC |
71 | fRank += delta; |
72 | } | |
73 | ||
550d787e FC |
74 | public boolean isValidRank() { |
75 | return fRank != UNKNOWN_RANK; | |
76 | } | |
77 | ||
ff4ed569 FC |
78 | // ------------------------------------------------------------------------ |
79 | // Object | |
80 | // ------------------------------------------------------------------------ | |
81 | ||
82 | @Override | |
83 | public int hashCode() { | |
84 | int result = 17; | |
85 | result = 37 * result + fLocation.hashCode(); | |
86 | result = 37 * result + (int) (fRank ^ (fRank >>> 32)); | |
87 | return result; | |
88 | } | |
89 | ||
90 | @Override | |
91 | public boolean equals(Object other) { | |
92 | if (!(other instanceof TmfContext)) { | |
93 | return false; | |
94 | } | |
95 | TmfContext o = (TmfContext) other; | |
96 | return fLocation.equals(o.fLocation) && (fRank == o.fRank); | |
97 | } | |
98 | ||
99 | @Override | |
100 | public String toString() { | |
101 | return "[TmfContext(" + fLocation.toString() + "," + fRank + ")]"; | |
102 | } | |
103 | ||
104 | @Override | |
105 | public TmfContext clone() { | |
106 | TmfContext clone = null; | |
107 | try { | |
108 | clone = (TmfContext) super.clone(); | |
109 | clone.fLocation = fLocation.clone(); | |
110 | clone.fRank = fRank; | |
111 | } catch (CloneNotSupportedException e) { | |
112 | } | |
113 | return clone; | |
8c8bf09f ASL |
114 | } |
115 | ||
116 | } |