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