tmf: Clean up tmf.core.trace package
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfContext.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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.linuxtools.tmf.core.trace;
16
17 import org.eclipse.linuxtools.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 * @version 1.0
26 * @author Francois Chouinard
27 *
28 * @see ITmfLocation
29 */
30 public class TmfContext implements ITmfContext {
31
32 // ------------------------------------------------------------------------
33 // Attributes
34 // ------------------------------------------------------------------------
35
36 // The trace location
37 private ITmfLocation fLocation;
38
39 // The event rank
40 private long fRank;
41
42 // ------------------------------------------------------------------------
43 // Constructors
44 // ------------------------------------------------------------------------
45
46 /**
47 * Default constructor
48 */
49 public TmfContext() {
50 this(null, UNKNOWN_RANK);
51 }
52
53 /**
54 * Simple constructor (unknown rank)
55 *
56 * @param location the event location
57 * @since 3.0
58 */
59 public TmfContext(final ITmfLocation location) {
60 this(location, UNKNOWN_RANK);
61 }
62
63 /**
64 * Full constructor
65 *
66 * @param location the event location
67 * @param rank the event rank
68 * @since 3.0
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 /**
93 * @since 3.0
94 */
95 @Override
96 public ITmfLocation getLocation() {
97 return fLocation;
98 }
99
100 /**
101 * @since 3.0
102 */
103 @Override
104 public void setLocation(final ITmfLocation location) {
105 fLocation = location;
106 }
107
108 @Override
109 public long getRank() {
110 return fRank;
111 }
112
113 @Override
114 public void setRank(final long rank) {
115 fRank = rank;
116 }
117
118 @Override
119 public void increaseRank() {
120 if (hasValidRank()) {
121 fRank++;
122 }
123 }
124
125 @Override
126 public boolean hasValidRank() {
127 return fRank != UNKNOWN_RANK;
128 }
129
130 @Override
131 public void dispose() {
132 }
133
134 // ------------------------------------------------------------------------
135 // Object
136 // ------------------------------------------------------------------------
137
138 @Override
139 public int hashCode() {
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));
144 return result;
145 }
146
147 @Override
148 public boolean equals(final Object obj) {
149 if (this == obj) {
150 return true;
151 }
152 if (obj == null) {
153 return false;
154 }
155 if (getClass() != obj.getClass()) {
156 return false;
157 }
158 final TmfContext other = (TmfContext) obj;
159 if (fLocation == null) {
160 if (other.fLocation != null) {
161 return false;
162 }
163 } else if (!fLocation.equals(other.fLocation)) {
164 return false;
165 }
166 if (fRank != other.fRank) {
167 return false;
168 }
169 return true;
170 }
171
172 @Override
173 @SuppressWarnings("nls")
174 public String toString() {
175 return "TmfContext [fLocation=" + fLocation + ", fRank=" + fRank + "]";
176 }
177
178 }
This page took 0.035277 seconds and 6 git commands to generate.