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 | * @version 1.0 |
26 | * @author Francois Chouinard | |
27 | * | |
f7703ed6 | 28 | * @see ITmfLocation |
8c8bf09f | 29 | */ |
81a2d02e | 30 | public class TmfContext implements ITmfContext { |
8c8bf09f | 31 | |
cbdacf03 FC |
32 | // ------------------------------------------------------------------------ |
33 | // Attributes | |
34 | // ------------------------------------------------------------------------ | |
35 | ||
36 | // The trace location | |
1e1bef82 | 37 | private ITmfLocation fLocation; |
cbdacf03 FC |
38 | |
39 | // The event rank | |
948b0607 FC |
40 | private long fRank; |
41 | ||
42 | // ------------------------------------------------------------------------ | |
43 | // Constructors | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
cbdacf03 FC |
46 | /** |
47 | * Default constructor | |
48 | */ | |
49 | public TmfContext() { | |
50 | this(null, UNKNOWN_RANK); | |
948b0607 FC |
51 | } |
52 | ||
cbdacf03 FC |
53 | /** |
54 | * Simple constructor (unknown rank) | |
1e1bef82 | 55 | * |
cbdacf03 | 56 | * @param location the event location |
a3db8436 | 57 | * @since 3.0 |
cbdacf03 | 58 | */ |
1e1bef82 | 59 | public TmfContext(final ITmfLocation location) { |
948b0607 FC |
60 | this(location, UNKNOWN_RANK); |
61 | } | |
62 | ||
cbdacf03 FC |
63 | /** |
64 | * Full constructor | |
1e1bef82 | 65 | * |
cbdacf03 FC |
66 | * @param location the event location |
67 | * @param rank the event rank | |
a3db8436 | 68 | * @since 3.0 |
cbdacf03 | 69 | */ |
1e1bef82 | 70 | public TmfContext(final ITmfLocation location, final long rank) { |
cbdacf03 FC |
71 | fLocation = location; |
72 | fRank = rank; | |
948b0607 FC |
73 | } |
74 | ||
cbdacf03 FC |
75 | /** |
76 | * Copy constructor | |
1e1bef82 | 77 | * |
cbdacf03 FC |
78 | * @param context the other context |
79 | */ | |
5d837f9b | 80 | public TmfContext(final TmfContext context) { |
0316808c | 81 | if (context == null) { |
5d837f9b | 82 | throw new IllegalArgumentException(); |
0316808c | 83 | } |
5d837f9b FC |
84 | fLocation = context.fLocation; |
85 | fRank = context.fRank; | |
cbdacf03 FC |
86 | } |
87 | ||
948b0607 FC |
88 | // ------------------------------------------------------------------------ |
89 | // ITmfContext | |
90 | // ------------------------------------------------------------------------ | |
91 | ||
a3db8436 AM |
92 | /** |
93 | * @since 3.0 | |
94 | */ | |
948b0607 | 95 | @Override |
1e1bef82 | 96 | public ITmfLocation getLocation() { |
cbdacf03 | 97 | return fLocation; |
948b0607 FC |
98 | } |
99 | ||
a3db8436 AM |
100 | /** |
101 | * @since 3.0 | |
102 | */ | |
948b0607 | 103 | @Override |
1e1bef82 | 104 | public void setLocation(final ITmfLocation location) { |
948b0607 FC |
105 | fLocation = location; |
106 | } | |
107 | ||
108 | @Override | |
cbdacf03 FC |
109 | public long getRank() { |
110 | return fRank; | |
948b0607 FC |
111 | } |
112 | ||
113 | @Override | |
5d837f9b | 114 | public void setRank(final long rank) { |
948b0607 FC |
115 | fRank = rank; |
116 | } | |
117 | ||
118 | @Override | |
cbdacf03 | 119 | public void increaseRank() { |
0316808c | 120 | if (hasValidRank()) { |
cbdacf03 | 121 | fRank++; |
0316808c | 122 | } |
948b0607 FC |
123 | } |
124 | ||
125 | @Override | |
cbdacf03 FC |
126 | public boolean hasValidRank() { |
127 | return fRank != UNKNOWN_RANK; | |
948b0607 FC |
128 | } |
129 | ||
130 | @Override | |
cbdacf03 | 131 | public void dispose() { |
948b0607 FC |
132 | } |
133 | ||
134 | // ------------------------------------------------------------------------ | |
135 | // Object | |
136 | // ------------------------------------------------------------------------ | |
ff4ed569 FC |
137 | |
138 | @Override | |
139 | public int hashCode() { | |
cbdacf03 FC |
140 | final int prime = 31; |
141 | int result = 1; | |
142 | result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode()); | |
143 | result = prime * result + (int) (fRank ^ (fRank >>> 32)); | |
948b0607 | 144 | return result; |
ff4ed569 | 145 | } |
948b0607 | 146 | |
ff4ed569 | 147 | @Override |
5d837f9b | 148 | public boolean equals(final Object obj) { |
0316808c | 149 | if (this == obj) { |
948b0607 | 150 | return true; |
0316808c FC |
151 | } |
152 | if (obj == null) { | |
948b0607 | 153 | return false; |
0316808c FC |
154 | } |
155 | if (getClass() != obj.getClass()) { | |
cbdacf03 | 156 | return false; |
0316808c | 157 | } |
5d837f9b | 158 | final TmfContext other = (TmfContext) obj; |
cbdacf03 | 159 | if (fLocation == null) { |
0316808c | 160 | if (other.fLocation != null) { |
cbdacf03 | 161 | return false; |
0316808c FC |
162 | } |
163 | } else if (!fLocation.equals(other.fLocation)) { | |
cbdacf03 | 164 | return false; |
0316808c FC |
165 | } |
166 | if (fRank != other.fRank) { | |
cbdacf03 | 167 | return false; |
0316808c | 168 | } |
cbdacf03 | 169 | return true; |
ff4ed569 | 170 | } |
948b0607 FC |
171 | |
172 | @Override | |
3b38ea61 | 173 | @SuppressWarnings("nls") |
ff4ed569 | 174 | public String toString() { |
cbdacf03 | 175 | return "TmfContext [fLocation=" + fLocation + ", fRank=" + fRank + "]"; |
ff4ed569 | 176 | } |
8c8bf09f ASL |
177 | |
178 | } |