Remove the generic location (replace by Comparable)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfCheckpoint.java
CommitLineData
8c8bf09f 1/*******************************************************************************
5d837f9b 2 * Copyright (c) 2009, 2012 Ericsson
6256d8ad 3 *
8c8bf09f
ASL
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
6256d8ad 8 *
8c8bf09f
ASL
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
5d837f9b
FC
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 ******************************************************************************/
8c8bf09f 13
6c13869b 14package org.eclipse.linuxtools.tmf.core.trace;
8c8bf09f 15
4df4581d 16import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
8c8bf09f
ASL
17
18/**
2848c377
FC
19 * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
20 * to a generic location.
6256d8ad 21 *
f7703ed6
FC
22 * @version 1.0
23 * @author Francois Chouinard
24 *
f7703ed6
FC
25 * @see ITmfLocation
26 * @see ITmfTimestamp
8c8bf09f 27 */
0316808c 28public class TmfCheckpoint implements ITmfCheckpoint, Cloneable {
8c8bf09f
ASL
29
30 // ------------------------------------------------------------------------
31 // Attributes
32 // ------------------------------------------------------------------------
cbdacf03 33
d905a64a
FC
34 // The checkpoint context
35 private ITmfContext fContext;
5d837f9b
FC
36
37 // The checkpoint timestamp
4df4581d 38 private ITmfTimestamp fTimestamp;
8c8bf09f
ASL
39
40 // ------------------------------------------------------------------------
41 // Constructors
42 // ------------------------------------------------------------------------
43
5d837f9b
FC
44 /**
45 * Default constructor
46 */
ff4ed569 47 @SuppressWarnings("unused")
cbdacf03 48 private TmfCheckpoint() {
ff4ed569
FC
49 }
50
8c8bf09f 51 /**
5d837f9b 52 * Full constructor
6256d8ad 53 *
5d837f9b 54 * @param timestamp the checkpoint timestamp
063f0d27 55 * @param context the corresponding trace location
8c8bf09f 56 */
d905a64a 57 public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfContext context) {
5d837f9b 58 fTimestamp = timestamp;
d905a64a 59 fContext = context;
8c8bf09f
ASL
60 }
61
ff4ed569 62 /**
5d837f9b 63 * Copy constructor
6256d8ad 64 *
ff4ed569
FC
65 * @param other the other checkpoint
66 */
cbdacf03 67 public TmfCheckpoint(final TmfCheckpoint other) {
0316808c 68 if (other == null) {
cbdacf03 69 throw new IllegalArgumentException();
0316808c 70 }
5d837f9b 71 fTimestamp = other.fTimestamp;
d905a64a 72 fContext = other.fContext;
5d837f9b
FC
73 }
74
75 // ------------------------------------------------------------------------
76 // Cloneable
77 // ------------------------------------------------------------------------
78
79 /* (non-Javadoc)
80 * @see java.lang.Object#clone()
81 */
82 @Override
83 public TmfCheckpoint clone() {
84 TmfCheckpoint clone = null;
85 try {
86 clone = (TmfCheckpoint) super.clone();
d905a64a 87 clone.fContext = (fContext != null) ? fContext.clone() : null;
5d837f9b
FC
88 clone.fTimestamp = (fTimestamp != null) ? fTimestamp.clone() : null;
89 } catch (final CloneNotSupportedException e) {
90 }
91 return clone;
ff4ed569
FC
92 }
93
8c8bf09f 94 // ------------------------------------------------------------------------
8ca8c4f1 95 // ITmfCheckpoint
8c8bf09f
ASL
96 // ------------------------------------------------------------------------
97
8ca8c4f1
FC
98 /* (non-Javadoc)
99 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getTimestamp()
8c8bf09f 100 */
5d837f9b 101 @Override
4df4581d 102 public ITmfTimestamp getTimestamp() {
8c8bf09f
ASL
103 return fTimestamp;
104 }
105
8ca8c4f1
FC
106 /* (non-Javadoc)
107 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
8c8bf09f 108 */
5d837f9b 109 @Override
408e65d2
FC
110 public ITmfContext getContext() {
111 return fContext;
d905a64a
FC
112 }
113
114 /* (non-Javadoc)
408e65d2 115 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
d905a64a 116 */
37419bf3 117 @Override
1e1bef82 118 public ITmfLocation getLocation() {
408e65d2 119 return fContext.getLocation();
8c8bf09f
ASL
120 }
121
cbd4ad82 122 // ------------------------------------------------------------------------
5d837f9b 123 // Comparable
cbd4ad82
FC
124 // ------------------------------------------------------------------------
125
8ca8c4f1
FC
126 /* (non-Javadoc)
127 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#compareTo(org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint)
6256d8ad 128 *
8ca8c4f1
FC
129 * Compares the checkpoints timestamp. If either is null, compares the
130 * trace checkpoints locations.
131 */
550d787e 132 @Override
ff1ccee6 133 @SuppressWarnings({ "unchecked", "rawtypes" })
5d837f9b
FC
134 public int compareTo(final ITmfCheckpoint other) {
135 if (fTimestamp == null || other.getTimestamp() == null) {
6bab4511
AM
136 final Comparable location1 = getLocation().getLocationData();
137 final Comparable location2 = other.getLocation().getLocationData();
5d837f9b 138 return location1.compareTo(location2);
cbdacf03 139 }
5d837f9b 140 return fTimestamp.compareTo(other.getTimestamp(), false);
550d787e 141 }
cbdacf03 142
5d837f9b
FC
143 // ------------------------------------------------------------------------
144 // Object
145 // ------------------------------------------------------------------------
146
8ca8c4f1
FC
147 /* (non-Javadoc)
148 * @see java.lang.Object#hashCode()
149 */
cbd4ad82
FC
150 @Override
151 public int hashCode() {
5d837f9b
FC
152 final int prime = 31;
153 int result = 1;
d905a64a 154 result = prime * result + ((fContext == null) ? 0 : fContext.hashCode());
5d837f9b
FC
155 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
156 return result;
cbd4ad82 157 }
cbdacf03 158
8ca8c4f1
FC
159 /* (non-Javadoc)
160 * @see java.lang.Object#equals(java.lang.Object)
161 */
cbd4ad82 162 @Override
5d837f9b 163 public boolean equals(final Object obj) {
0316808c 164 if (this == obj) {
5d837f9b 165 return true;
0316808c
FC
166 }
167 if (obj == null) {
5d837f9b 168 return false;
0316808c
FC
169 }
170 if (!(obj instanceof TmfCheckpoint)) {
cbdacf03 171 return false;
0316808c 172 }
5d837f9b 173 final TmfCheckpoint other = (TmfCheckpoint) obj;
d905a64a
FC
174 if (fContext == null) {
175 if (other.fContext != null) {
5d837f9b 176 return false;
0316808c 177 }
d905a64a 178 } else if (!fContext.equals(other.fContext)) {
5d837f9b 179 return false;
0316808c 180 }
5d837f9b 181 if (fTimestamp == null) {
0316808c 182 if (other.fTimestamp != null) {
5d837f9b 183 return false;
0316808c
FC
184 }
185 } else if (!fTimestamp.equals(other.fTimestamp)) {
5d837f9b 186 return false;
0316808c 187 }
5d837f9b 188 return true;
cbd4ad82 189 }
cbdacf03 190
8ca8c4f1
FC
191 /* (non-Javadoc)
192 * @see java.lang.Object#toString()
193 */
ff4ed569 194 @Override
3b38ea61 195 @SuppressWarnings("nls")
ff4ed569 196 public String toString() {
d905a64a 197 return "TmfCheckpoint [fContext=" + fContext + ", fTimestamp=" + fTimestamp + "]";
8c8bf09f
ASL
198 }
199
200}
This page took 0.052192 seconds and 5 git commands to generate.