Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2009, 2014 Ericsson |
1e1bef82 | 3 | * |
8c8bf09f ASL |
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 | |
1e1bef82 | 8 | * |
8c8bf09f ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
cbdacf03 | 11 | * Francois Chouinard - Updated as per TMF Trace Model 1.0 |
ea271da6 | 12 | * Patrick Tasse - Updated for removal of context clone |
8c8bf09f ASL |
13 | *******************************************************************************/ |
14 | ||
2bdf0193 | 15 | package org.eclipse.tracecompass.tmf.core.trace; |
8c8bf09f | 16 | |
2bdf0193 | 17 | import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation; |
a3db8436 | 18 | |
8c8bf09f | 19 | /** |
2848c377 FC |
20 | * A basic implementation of ITmfContext. |
21 | * <p> | |
22 | * It ties a trace location to an event rank. The context should be enough to | |
23 | * restore the trace state so the corresponding event can be read. | |
1e1bef82 | 24 | * |
f7703ed6 FC |
25 | * @author Francois Chouinard |
26 | * | |
f7703ed6 | 27 | * @see ITmfLocation |
8c8bf09f | 28 | */ |
81a2d02e | 29 | public class TmfContext implements ITmfContext { |
8c8bf09f | 30 | |
cbdacf03 FC |
31 | // ------------------------------------------------------------------------ |
32 | // Attributes | |
33 | // ------------------------------------------------------------------------ | |
34 | ||
35 | // The trace location | |
1e1bef82 | 36 | private ITmfLocation fLocation; |
cbdacf03 FC |
37 | |
38 | // The event rank | |
948b0607 FC |
39 | private long fRank; |
40 | ||
41 | // ------------------------------------------------------------------------ | |
42 | // Constructors | |
43 | // ------------------------------------------------------------------------ | |
44 | ||
cbdacf03 FC |
45 | /** |
46 | * Default constructor | |
47 | */ | |
48 | public TmfContext() { | |
49 | this(null, UNKNOWN_RANK); | |
948b0607 FC |
50 | } |
51 | ||
cbdacf03 FC |
52 | /** |
53 | * Simple constructor (unknown rank) | |
1e1bef82 | 54 | * |
cbdacf03 FC |
55 | * @param location the event location |
56 | */ | |
1e1bef82 | 57 | public TmfContext(final ITmfLocation location) { |
948b0607 FC |
58 | this(location, UNKNOWN_RANK); |
59 | } | |
60 | ||
cbdacf03 FC |
61 | /** |
62 | * Full constructor | |
1e1bef82 | 63 | * |
cbdacf03 FC |
64 | * @param location the event location |
65 | * @param rank the event rank | |
66 | */ | |
1e1bef82 | 67 | public TmfContext(final ITmfLocation location, final long rank) { |
cbdacf03 FC |
68 | fLocation = location; |
69 | fRank = rank; | |
948b0607 FC |
70 | } |
71 | ||
cbdacf03 FC |
72 | /** |
73 | * Copy constructor | |
1e1bef82 | 74 | * |
cbdacf03 FC |
75 | * @param context the other context |
76 | */ | |
5d837f9b | 77 | public TmfContext(final TmfContext context) { |
0316808c | 78 | if (context == null) { |
5d837f9b | 79 | throw new IllegalArgumentException(); |
0316808c | 80 | } |
5d837f9b FC |
81 | fLocation = context.fLocation; |
82 | fRank = context.fRank; | |
cbdacf03 FC |
83 | } |
84 | ||
948b0607 FC |
85 | // ------------------------------------------------------------------------ |
86 | // ITmfContext | |
87 | // ------------------------------------------------------------------------ | |
88 | ||
89 | @Override | |
1e1bef82 | 90 | public ITmfLocation getLocation() { |
cbdacf03 | 91 | return fLocation; |
948b0607 FC |
92 | } |
93 | ||
94 | @Override | |
1e1bef82 | 95 | public void setLocation(final ITmfLocation location) { |
948b0607 FC |
96 | fLocation = location; |
97 | } | |
98 | ||
99 | @Override | |
cbdacf03 FC |
100 | public long getRank() { |
101 | return fRank; | |
948b0607 FC |
102 | } |
103 | ||
104 | @Override | |
5d837f9b | 105 | public void setRank(final long rank) { |
948b0607 FC |
106 | fRank = rank; |
107 | } | |
108 | ||
109 | @Override | |
cbdacf03 | 110 | public void increaseRank() { |
0316808c | 111 | if (hasValidRank()) { |
cbdacf03 | 112 | fRank++; |
0316808c | 113 | } |
948b0607 FC |
114 | } |
115 | ||
116 | @Override | |
cbdacf03 FC |
117 | public boolean hasValidRank() { |
118 | return fRank != UNKNOWN_RANK; | |
948b0607 FC |
119 | } |
120 | ||
121 | @Override | |
cbdacf03 | 122 | public void dispose() { |
948b0607 FC |
123 | } |
124 | ||
125 | // ------------------------------------------------------------------------ | |
126 | // Object | |
127 | // ------------------------------------------------------------------------ | |
ff4ed569 FC |
128 | |
129 | @Override | |
130 | public int hashCode() { | |
cbdacf03 FC |
131 | final int prime = 31; |
132 | int result = 1; | |
133 | result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode()); | |
134 | result = prime * result + (int) (fRank ^ (fRank >>> 32)); | |
948b0607 | 135 | return result; |
ff4ed569 | 136 | } |
948b0607 | 137 | |
ff4ed569 | 138 | @Override |
5d837f9b | 139 | public boolean equals(final Object obj) { |
0316808c | 140 | if (this == obj) { |
948b0607 | 141 | return true; |
0316808c FC |
142 | } |
143 | if (obj == null) { | |
948b0607 | 144 | return false; |
0316808c FC |
145 | } |
146 | if (getClass() != obj.getClass()) { | |
cbdacf03 | 147 | return false; |
0316808c | 148 | } |
5d837f9b | 149 | final TmfContext other = (TmfContext) obj; |
cbdacf03 | 150 | if (fLocation == null) { |
0316808c | 151 | if (other.fLocation != null) { |
cbdacf03 | 152 | return false; |
0316808c FC |
153 | } |
154 | } else if (!fLocation.equals(other.fLocation)) { | |
cbdacf03 | 155 | return false; |
0316808c FC |
156 | } |
157 | if (fRank != other.fRank) { | |
cbdacf03 | 158 | return false; |
0316808c | 159 | } |
cbdacf03 | 160 | return true; |
ff4ed569 | 161 | } |
948b0607 FC |
162 | |
163 | @Override | |
3b38ea61 | 164 | @SuppressWarnings("nls") |
ff4ed569 | 165 | public String toString() { |
cbdacf03 | 166 | return "TmfContext [fLocation=" + fLocation + ", fRank=" + fRank + "]"; |
ff4ed569 | 167 | } |
8c8bf09f ASL |
168 | |
169 | } |