Refactor TmfCheckpoint and dependencies (+JUnits)
[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
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
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/**
19 * <b><u>TmfCheckpoint</u></b>
20 * <p>
ff4ed569 21 * This class maps an event timestamp to a generic location.
8c8bf09f 22 */
5d837f9b 23public class TmfCheckpoint implements ITmfCheckpoint {
8c8bf09f
ASL
24
25 // ------------------------------------------------------------------------
26 // Attributes
27 // ------------------------------------------------------------------------
cbdacf03 28
5d837f9b
FC
29 // The checkpoint location
30 private ITmfLocation<? extends Comparable<?>> fLocation;
31
32 // The checkpoint timestamp
4df4581d 33 private ITmfTimestamp fTimestamp;
8c8bf09f
ASL
34
35 // ------------------------------------------------------------------------
36 // Constructors
37 // ------------------------------------------------------------------------
38
5d837f9b
FC
39 /**
40 * Default constructor
41 */
ff4ed569 42 @SuppressWarnings("unused")
cbdacf03 43 private TmfCheckpoint() {
ff4ed569
FC
44 }
45
8c8bf09f 46 /**
5d837f9b
FC
47 * Full constructor
48 *
49 * @param timestamp the checkpoint timestamp
ff4ed569 50 * @param location the corresponding trace location
8c8bf09f 51 */
5d837f9b
FC
52 public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation<? extends Comparable<?>> location) {
53 fTimestamp = timestamp;
8c8bf09f
ASL
54 fLocation = location;
55 }
56
ff4ed569 57 /**
5d837f9b 58 * Copy constructor
cbdacf03 59 *
ff4ed569
FC
60 * @param other the other checkpoint
61 */
cbdacf03
FC
62 public TmfCheckpoint(final TmfCheckpoint other) {
63 if (other == null)
64 throw new IllegalArgumentException();
5d837f9b
FC
65 fTimestamp = other.fTimestamp;
66 fLocation = other.fLocation;
67 }
68
69 // ------------------------------------------------------------------------
70 // Cloneable
71 // ------------------------------------------------------------------------
72
73 /* (non-Javadoc)
74 * @see java.lang.Object#clone()
75 */
76 @Override
77 public TmfCheckpoint clone() {
78 TmfCheckpoint clone = null;
79 try {
80 clone = (TmfCheckpoint) super.clone();
81 clone.fLocation = (fLocation != null) ? fLocation.clone() : null;
82 clone.fTimestamp = (fTimestamp != null) ? fTimestamp.clone() : null;
83 } catch (final CloneNotSupportedException e) {
84 }
85 return clone;
ff4ed569
FC
86 }
87
8c8bf09f 88 // ------------------------------------------------------------------------
8ca8c4f1 89 // ITmfCheckpoint
8c8bf09f
ASL
90 // ------------------------------------------------------------------------
91
8ca8c4f1
FC
92 /* (non-Javadoc)
93 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getTimestamp()
8c8bf09f 94 */
5d837f9b 95 @Override
4df4581d 96 public ITmfTimestamp getTimestamp() {
8c8bf09f
ASL
97 return fTimestamp;
98 }
99
8ca8c4f1
FC
100 /* (non-Javadoc)
101 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#getLocation()
8c8bf09f 102 */
5d837f9b 103 @Override
452ad365 104 public ITmfLocation<?> getLocation() {
8c8bf09f
ASL
105 return fLocation;
106 }
107
cbd4ad82 108 // ------------------------------------------------------------------------
5d837f9b 109 // Comparable
cbd4ad82
FC
110 // ------------------------------------------------------------------------
111
8ca8c4f1
FC
112 /* (non-Javadoc)
113 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint#compareTo(org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint)
114 *
115 * Compares the checkpoints timestamp. If either is null, compares the
116 * trace checkpoints locations.
117 */
550d787e 118 @Override
ff1ccee6 119 @SuppressWarnings({ "unchecked", "rawtypes" })
5d837f9b
FC
120 public int compareTo(final ITmfCheckpoint other) {
121 if (fTimestamp == null || other.getTimestamp() == null) {
122 final Comparable location1 = fLocation.getLocation();
123 final Comparable location2 = other.getLocation().getLocation();
124 return location1.compareTo(location2);
cbdacf03 125 }
5d837f9b 126 return fTimestamp.compareTo(other.getTimestamp(), false);
550d787e 127 }
cbdacf03 128
5d837f9b
FC
129 // ------------------------------------------------------------------------
130 // Object
131 // ------------------------------------------------------------------------
132
8ca8c4f1
FC
133 /* (non-Javadoc)
134 * @see java.lang.Object#hashCode()
135 */
cbd4ad82
FC
136 @Override
137 public int hashCode() {
5d837f9b
FC
138 final int prime = 31;
139 int result = 1;
140 result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
141 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
142 return result;
cbd4ad82 143 }
cbdacf03 144
8ca8c4f1
FC
145 /* (non-Javadoc)
146 * @see java.lang.Object#equals(java.lang.Object)
147 */
cbd4ad82 148 @Override
5d837f9b
FC
149 public boolean equals(final Object obj) {
150 if (this == obj)
151 return true;
152 if (obj == null)
153 return false;
154 if (!(obj instanceof TmfCheckpoint))
cbdacf03 155 return false;
5d837f9b
FC
156 final TmfCheckpoint other = (TmfCheckpoint) obj;
157 if (fLocation == null) {
158 if (other.fLocation != null)
159 return false;
160 } else if (!fLocation.equals(other.fLocation))
161 return false;
162 if (fTimestamp == null) {
163 if (other.fTimestamp != null)
164 return false;
165 } else if (!fTimestamp.equals(other.fTimestamp))
166 return false;
167 return true;
cbd4ad82 168 }
cbdacf03 169
8ca8c4f1
FC
170 /* (non-Javadoc)
171 * @see java.lang.Object#toString()
172 */
ff4ed569 173 @Override
3b38ea61 174 @SuppressWarnings("nls")
ff4ed569 175 public String toString() {
5d837f9b 176 return "TmfCheckpoint [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]";
8c8bf09f
ASL
177 }
178
179}
This page took 0.040472 seconds and 5 git commands to generate.