tmf: annotate TmfContext#location as nullable
[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 java.util.Objects;
18
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
21
22 /**
23 * A basic implementation of ITmfContext.
24 * <p>
25 * It ties a trace location to an event rank. The context should be enough to
26 * restore the trace state so the corresponding event can be read.
27 *
28 * @author Francois Chouinard
29 *
30 * @see ITmfLocation
31 */
32 public class TmfContext implements ITmfContext {
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
37
38 // The trace location
39 private @Nullable ITmfLocation fLocation;
40
41 // The event rank
42 private long fRank;
43
44 // ------------------------------------------------------------------------
45 // Constructors
46 // ------------------------------------------------------------------------
47
48 /**
49 * Default constructor
50 */
51 public TmfContext() {
52 this(null, UNKNOWN_RANK);
53 }
54
55 /**
56 * Simple constructor (unknown rank)
57 *
58 * @param location the event location
59 */
60 public TmfContext(final ITmfLocation location) {
61 this(location, UNKNOWN_RANK);
62 }
63
64 /**
65 * Full constructor
66 *
67 * @param location the event location
68 * @param rank the event rank
69 */
70 public TmfContext(final ITmfLocation location, final long rank) {
71 fLocation = location;
72 fRank = rank;
73 }
74
75 /**
76 * Copy constructor
77 *
78 * @param context the other context
79 */
80 public TmfContext(final TmfContext context) {
81 if (context == null) {
82 throw new IllegalArgumentException();
83 }
84 fLocation = context.fLocation;
85 fRank = context.fRank;
86 }
87
88 // ------------------------------------------------------------------------
89 // ITmfContext
90 // ------------------------------------------------------------------------
91
92 @Override
93 public @Nullable ITmfLocation getLocation() {
94 return fLocation;
95 }
96
97 @Override
98 public void setLocation(final ITmfLocation location) {
99 fLocation = location;
100 }
101
102 @Override
103 public long getRank() {
104 return fRank;
105 }
106
107 @Override
108 public void setRank(final long rank) {
109 fRank = rank;
110 }
111
112 @Override
113 public void increaseRank() {
114 if (hasValidRank()) {
115 fRank++;
116 }
117 }
118
119 @Override
120 public boolean hasValidRank() {
121 return fRank != UNKNOWN_RANK;
122 }
123
124 @Override
125 public void dispose() {
126 }
127
128 // ------------------------------------------------------------------------
129 // Object
130 // ------------------------------------------------------------------------
131
132 @Override
133 public int hashCode() {
134 return Objects.hash(fRank, fLocation);
135 }
136
137 @Override
138 public boolean equals(final Object obj) {
139 if (this == obj) {
140 return true;
141 }
142 if (obj == null) {
143 return false;
144 }
145 if (getClass() != obj.getClass()) {
146 return false;
147 }
148 final TmfContext other = (TmfContext) obj;
149 if (fRank != other.fRank) {
150 return false;
151 }
152 if (!Objects.equals(fLocation, other.fLocation)) {
153 return false;
154 }
155 return true;
156 }
157
158 @Override
159 @SuppressWarnings("nls")
160 public String toString() {
161 return "TmfContext [fLocation=" + fLocation + ", fRank=" + fRank + "]";
162 }
163
164 }
This page took 0.033511 seconds and 5 git commands to generate.