d62c5ee752dcd9239b2fded7784fef075a5b2db5
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / trace / TmfContext.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 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 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 * Patrick Tasse - Updated for removal of context clone
13 *******************************************************************************/
14
15 package org.eclipse.tracecompass.tmf.core.trace;
16
17 import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
18
19 /**
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.
24 *
25 * @author Francois Chouinard
26 *
27 * @see ITmfLocation
28 */
29 public class TmfContext implements ITmfContext {
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34
35 // The trace location
36 private ITmfLocation fLocation;
37
38 // The event rank
39 private long fRank;
40
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44
45 /**
46 * Default constructor
47 */
48 public TmfContext() {
49 this(null, UNKNOWN_RANK);
50 }
51
52 /**
53 * Simple constructor (unknown rank)
54 *
55 * @param location the event location
56 */
57 public TmfContext(final ITmfLocation location) {
58 this(location, UNKNOWN_RANK);
59 }
60
61 /**
62 * Full constructor
63 *
64 * @param location the event location
65 * @param rank the event rank
66 */
67 public TmfContext(final ITmfLocation location, final long rank) {
68 fLocation = location;
69 fRank = rank;
70 }
71
72 /**
73 * Copy constructor
74 *
75 * @param context the other context
76 */
77 public TmfContext(final TmfContext context) {
78 if (context == null) {
79 throw new IllegalArgumentException();
80 }
81 fLocation = context.fLocation;
82 fRank = context.fRank;
83 }
84
85 // ------------------------------------------------------------------------
86 // ITmfContext
87 // ------------------------------------------------------------------------
88
89 @Override
90 public ITmfLocation getLocation() {
91 return fLocation;
92 }
93
94 @Override
95 public void setLocation(final ITmfLocation location) {
96 fLocation = location;
97 }
98
99 @Override
100 public long getRank() {
101 return fRank;
102 }
103
104 @Override
105 public void setRank(final long rank) {
106 fRank = rank;
107 }
108
109 @Override
110 public void increaseRank() {
111 if (hasValidRank()) {
112 fRank++;
113 }
114 }
115
116 @Override
117 public boolean hasValidRank() {
118 return fRank != UNKNOWN_RANK;
119 }
120
121 @Override
122 public void dispose() {
123 }
124
125 // ------------------------------------------------------------------------
126 // Object
127 // ------------------------------------------------------------------------
128
129 @Override
130 public int hashCode() {
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));
135 return result;
136 }
137
138 @Override
139 public boolean equals(final Object obj) {
140 if (this == obj) {
141 return true;
142 }
143 if (obj == null) {
144 return false;
145 }
146 if (getClass() != obj.getClass()) {
147 return false;
148 }
149 final TmfContext other = (TmfContext) obj;
150 if (fLocation == null) {
151 if (other.fLocation != null) {
152 return false;
153 }
154 } else if (!fLocation.equals(other.fLocation)) {
155 return false;
156 }
157 if (fRank != other.fRank) {
158 return false;
159 }
160 return true;
161 }
162
163 @Override
164 @SuppressWarnings("nls")
165 public String toString() {
166 return "TmfContext [fLocation=" + fLocation + ", fRank=" + fRank + "]";
167 }
168
169 }
This page took 0.040847 seconds and 4 git commands to generate.