Minor API improvements
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfContext.java
CommitLineData
8c8bf09f 1/*******************************************************************************
cbdacf03 2 * Copyright (c) 2009, 2010, 2012 Ericsson
8c8bf09f
ASL
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
cbdacf03 11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
8c8bf09f
ASL
12 *******************************************************************************/
13
6c13869b 14package org.eclipse.linuxtools.tmf.core.trace;
8c8bf09f 15
8c8bf09f
ASL
16/**
17 * <b><u>TmfContext</u></b>
18 * <p>
19 * Trace context structure. It ties a trace location to an event rank. The
20 * context should be enough to restore the trace state so the corresponding
21 * event can be read.
22 */
cbd4ad82 23public class TmfContext implements ITmfContext, Cloneable {
8c8bf09f 24
cbdacf03
FC
25 // ------------------------------------------------------------------------
26 // Attributes
27 // ------------------------------------------------------------------------
28
29 // The trace location
948b0607 30 private ITmfLocation<? extends Comparable<?>> fLocation;
cbdacf03
FC
31
32 // The event rank
948b0607
FC
33 private long fRank;
34
35 // ------------------------------------------------------------------------
36 // Constructors
37 // ------------------------------------------------------------------------
38
cbdacf03
FC
39 /**
40 * Default constructor
41 */
42 public TmfContext() {
43 this(null, UNKNOWN_RANK);
948b0607
FC
44 }
45
cbdacf03
FC
46 /**
47 * Simple constructor (unknown rank)
48 *
49 * @param location the event location
50 */
5d837f9b 51 public TmfContext(final ITmfLocation<? extends Comparable<?>> location) {
948b0607
FC
52 this(location, UNKNOWN_RANK);
53 }
54
cbdacf03
FC
55 /**
56 * Full constructor
57 *
58 * @param location the event location
59 * @param rank the event rank
60 */
5d837f9b 61 public TmfContext(final ITmfLocation<? extends Comparable<?>> location, final long rank) {
cbdacf03
FC
62 fLocation = location;
63 fRank = rank;
948b0607
FC
64 }
65
cbdacf03
FC
66 /**
67 * Copy constructor
68 *
69 * @param context the other context
70 */
5d837f9b
FC
71 public TmfContext(final TmfContext context) {
72 if (context == null)
73 throw new IllegalArgumentException();
74 fLocation = context.fLocation;
75 fRank = context.fRank;
cbdacf03
FC
76 }
77
78 // ------------------------------------------------------------------------
79 // Cloneable
80 // ------------------------------------------------------------------------
81
82 /* (non-Javadoc)
83 * @see java.lang.Object#clone()
84 */
85 @Override
86 public TmfContext clone() {
87 TmfContext clone = null;
88 try {
89 clone = (TmfContext) super.clone();
5d837f9b 90 clone.fLocation = (fLocation != null) ? fLocation.clone() : null;
cbdacf03 91 clone.fRank = fRank;
5d837f9b 92 } catch (final CloneNotSupportedException e) {
cbdacf03
FC
93 }
94 return clone;
948b0607
FC
95 }
96
97 // ------------------------------------------------------------------------
98 // ITmfContext
99 // ------------------------------------------------------------------------
100
cbdacf03
FC
101 /* (non-Javadoc)
102 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation()
103 */
948b0607 104 @Override
cbdacf03
FC
105 public ITmfLocation<? extends Comparable<?>> getLocation() {
106 return fLocation;
948b0607
FC
107 }
108
cbdacf03
FC
109 /* (non-Javadoc)
110 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setLocation(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation)
111 */
948b0607 112 @Override
5d837f9b 113 public void setLocation(final ITmfLocation<? extends Comparable<?>> location) {
948b0607
FC
114 fLocation = location;
115 }
116
cbdacf03
FC
117 /* (non-Javadoc)
118 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank()
119 */
948b0607 120 @Override
cbdacf03
FC
121 public long getRank() {
122 return fRank;
948b0607
FC
123 }
124
cbdacf03
FC
125 /* (non-Javadoc)
126 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long)
127 */
948b0607 128 @Override
5d837f9b 129 public void setRank(final long rank) {
948b0607
FC
130 fRank = rank;
131 }
132
cbdacf03
FC
133 /* (non-Javadoc)
134 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank()
135 */
948b0607 136 @Override
cbdacf03
FC
137 public void increaseRank() {
138 if (hasValidRank())
139 fRank++;
948b0607
FC
140 }
141
cbdacf03
FC
142 /* (non-Javadoc)
143 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank()
144 */
948b0607 145 @Override
cbdacf03
FC
146 public boolean hasValidRank() {
147 return fRank != UNKNOWN_RANK;
948b0607
FC
148 }
149
cbdacf03
FC
150 /* (non-Javadoc)
151 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose()
152 */
948b0607 153 @Override
cbdacf03 154 public void dispose() {
948b0607
FC
155 }
156
157 // ------------------------------------------------------------------------
158 // Object
159 // ------------------------------------------------------------------------
ff4ed569 160
cbdacf03
FC
161 /* (non-Javadoc)
162 * @see java.lang.Object#hashCode()
163 */
ff4ed569
FC
164 @Override
165 public int hashCode() {
cbdacf03
FC
166 final int prime = 31;
167 int result = 1;
168 result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
169 result = prime * result + (int) (fRank ^ (fRank >>> 32));
948b0607 170 return result;
ff4ed569 171 }
948b0607 172
cbdacf03
FC
173 /* (non-Javadoc)
174 * @see java.lang.Object#equals(java.lang.Object)
175 */
ff4ed569 176 @Override
5d837f9b 177 public boolean equals(final Object obj) {
cbdacf03 178 if (this == obj)
948b0607 179 return true;
cbdacf03 180 if (obj == null)
948b0607 181 return false;
cbdacf03
FC
182 if (getClass() != obj.getClass())
183 return false;
5d837f9b 184 final TmfContext other = (TmfContext) obj;
cbdacf03
FC
185 if (fLocation == null) {
186 if (other.fLocation != null)
187 return false;
188 } else if (!fLocation.equals(other.fLocation))
189 return false;
190 if (fRank != other.fRank)
191 return false;
192 return true;
ff4ed569 193 }
948b0607 194
cbdacf03
FC
195 /* (non-Javadoc)
196 * @see java.lang.Object#toString()
197 */
948b0607 198 @Override
3b38ea61 199 @SuppressWarnings("nls")
ff4ed569 200 public String toString() {
cbdacf03 201 return "TmfContext [fLocation=" + fLocation + ", fRank=" + fRank + "]";
ff4ed569 202 }
8c8bf09f
ASL
203
204}
This page took 0.041376 seconds and 5 git commands to generate.