Remove all existing @since annotations
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / trace / indexer / checkpoint / TmfCheckpoint.java
CommitLineData
8c8bf09f 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2009, 2014 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 11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
ea271da6 12 * Patrick Tasse - Updated for location in checkpoint
5d837f9b 13 ******************************************************************************/
8c8bf09f 14
2bdf0193 15package org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint;
8c8bf09f 16
032ecd45
MAL
17import java.nio.ByteBuffer;
18
2bdf0193
AM
19import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
20import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
21import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
8c8bf09f
ASL
22
23/**
2848c377
FC
24 * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
25 * to a generic location.
6256d8ad 26 *
f7703ed6
FC
27 * @see ITmfLocation
28 * @see ITmfTimestamp
a3db8436
AM
29 *
30 * @author Francois Chouinard
8c8bf09f 31 */
a12b0e0f 32public class TmfCheckpoint implements ITmfCheckpoint {
8c8bf09f
ASL
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
cbdacf03 37
ea271da6
PT
38 // The checkpoint location
39 private final ITmfLocation fLocation;
5d837f9b
FC
40
41 // The checkpoint timestamp
a12b0e0f 42 private final ITmfTimestamp fTimestamp;
8c8bf09f 43
032ecd45
MAL
44 private final long fCheckpointRank;
45
8c8bf09f
ASL
46 // ------------------------------------------------------------------------
47 // Constructors
48 // ------------------------------------------------------------------------
49
8c8bf09f 50 /**
5d837f9b 51 * Full constructor
6256d8ad 52 *
032ecd45
MAL
53 * @param timestamp
54 * the checkpoint timestamp
55 * @param location
56 * the corresponding trace location
57 * @param checkpointRank
58 * the rank of the checkpoint
032ecd45
MAL
59 */
60 public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation location, long checkpointRank) {
61 fTimestamp = timestamp;
62 fLocation = location;
63 fCheckpointRank = checkpointRank;
64 }
65
66 /**
67 * Constructs a checkpoint using also a byte buffer to read the rank from
68 * disk.
69 *
70 * @param timestamp
71 * the checkpoint timestamp
72 * @param location
73 * the corresponding trace location
74 * @param bufferIn
75 * the byte buffer to read from
8c8bf09f 76 */
032ecd45 77 public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation location, ByteBuffer bufferIn) {
5d837f9b 78 fTimestamp = timestamp;
ea271da6 79 fLocation = location;
032ecd45 80 fCheckpointRank = bufferIn.getLong();
8c8bf09f
ASL
81 }
82
ff4ed569 83 /**
5d837f9b 84 * Copy constructor
6256d8ad 85 *
ff4ed569
FC
86 * @param other the other checkpoint
87 */
cbdacf03 88 public TmfCheckpoint(final TmfCheckpoint other) {
0316808c 89 if (other == null) {
cbdacf03 90 throw new IllegalArgumentException();
0316808c 91 }
5d837f9b 92 fTimestamp = other.fTimestamp;
ea271da6 93 fLocation = other.fLocation;
032ecd45 94 fCheckpointRank = other.fCheckpointRank;
5d837f9b
FC
95 }
96
8c8bf09f 97 // ------------------------------------------------------------------------
8ca8c4f1 98 // ITmfCheckpoint
8c8bf09f
ASL
99 // ------------------------------------------------------------------------
100
5d837f9b 101 @Override
4df4581d 102 public ITmfTimestamp getTimestamp() {
8c8bf09f
ASL
103 return fTimestamp;
104 }
105
37419bf3 106 @Override
1e1bef82 107 public ITmfLocation getLocation() {
ea271da6 108 return fLocation;
8c8bf09f
ASL
109 }
110
cbd4ad82 111 // ------------------------------------------------------------------------
5d837f9b 112 // Comparable
cbd4ad82
FC
113 // ------------------------------------------------------------------------
114
550d787e 115 @Override
ff1ccee6 116 @SuppressWarnings({ "unchecked", "rawtypes" })
5d837f9b 117 public int compareTo(final ITmfCheckpoint other) {
3eade83c
BH
118 int comp = 0;
119 if ((fTimestamp != null) && (other.getTimestamp() != null)) {
065cc19b 120 comp = fTimestamp.compareTo(other.getTimestamp());
3eade83c
BH
121 if (comp != 0) {
122 return comp;
123 }
124 // compare locations if timestamps are the same
cbdacf03 125 }
3eade83c 126
ea271da6 127 if ((fLocation == null) && (other.getLocation() == null)) {
3eade83c
BH
128 return 0;
129 }
130
131 // treat location of other as null location which is before any location
ea271da6 132 if ((fLocation != null) && (other.getLocation() == null)) {
3eade83c
BH
133 return 1;
134 }
135
136 // treat this as null location which is before any other locations
ea271da6 137 if ((fLocation == null) && (other.getLocation() != null)) {
3eade83c
BH
138 return -1;
139 }
140
141 // compare location
142 final Comparable location1 = getLocation().getLocationInfo();
143 final Comparable location2 = other.getLocation().getLocationInfo();
144 return location1.compareTo(location2);
550d787e 145 }
cbdacf03 146
5d837f9b
FC
147 // ------------------------------------------------------------------------
148 // Object
149 // ------------------------------------------------------------------------
150
cbd4ad82
FC
151 @Override
152 public int hashCode() {
5d837f9b
FC
153 final int prime = 31;
154 int result = 1;
ea271da6 155 result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
5d837f9b
FC
156 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
157 return result;
cbd4ad82 158 }
cbdacf03 159
cbd4ad82 160 @Override
5d837f9b 161 public boolean equals(final Object obj) {
0316808c 162 if (this == obj) {
5d837f9b 163 return true;
0316808c
FC
164 }
165 if (obj == null) {
5d837f9b 166 return false;
0316808c
FC
167 }
168 if (!(obj instanceof TmfCheckpoint)) {
cbdacf03 169 return false;
0316808c 170 }
5d837f9b 171 final TmfCheckpoint other = (TmfCheckpoint) obj;
ea271da6
PT
172 if (fLocation == null) {
173 if (other.fLocation != null) {
5d837f9b 174 return false;
0316808c 175 }
ea271da6 176 } else if (!fLocation.equals(other.fLocation)) {
5d837f9b 177 return false;
0316808c 178 }
5d837f9b 179 if (fTimestamp == null) {
0316808c 180 if (other.fTimestamp != null) {
5d837f9b 181 return false;
0316808c
FC
182 }
183 } else if (!fTimestamp.equals(other.fTimestamp)) {
5d837f9b 184 return false;
0316808c 185 }
5d837f9b 186 return true;
cbd4ad82 187 }
cbdacf03 188
ff4ed569 189 @Override
3b38ea61 190 @SuppressWarnings("nls")
ff4ed569 191 public String toString() {
032ecd45 192 return getClass().getSimpleName() + " [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + ", fCheckpointRank=" + fCheckpointRank + "]";
8c8bf09f
ASL
193 }
194
032ecd45
MAL
195 @Override
196 public void serialize(ByteBuffer bufferOut) {
197 fLocation.serialize(bufferOut);
198 // Always serialize as base TmfTimestamp, this should be sufficient for indexing.
199 // If not, we can add API for the test to restore the time stamp, similarly to the location.
200 TmfTimestamp t = new TmfTimestamp(fTimestamp);
201 t.serialize(bufferOut);
202 bufferOut.putLong(fCheckpointRank);
203 }
204
032ecd45
MAL
205 @Override
206 public long getCheckpointRank() {
207 return fCheckpointRank;
208 }
8c8bf09f 209}
This page took 0.087175 seconds and 5 git commands to generate.