1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 * Patrick Tasse - Updated for location in checkpoint
13 ******************************************************************************/
15 package org
.eclipse
.tracecompass
.tmf
.core
.trace
.indexer
.checkpoint
;
17 import java
.nio
.ByteBuffer
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
24 * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
25 * to a generic location.
30 * @author Francois Chouinard
32 public class TmfCheckpoint
implements ITmfCheckpoint
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 // The checkpoint location
39 private final ITmfLocation fLocation
;
41 // The checkpoint timestamp
42 private final ITmfTimestamp fTimestamp
;
44 private final long fCheckpointRank
;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
54 * the checkpoint timestamp
56 * the corresponding trace location
57 * @param checkpointRank
58 * the rank of the checkpoint
60 public TmfCheckpoint(final ITmfTimestamp timestamp
, final ITmfLocation location
, long checkpointRank
) {
61 fTimestamp
= timestamp
;
63 fCheckpointRank
= checkpointRank
;
67 * Constructs a checkpoint using also a byte buffer to read the rank from
71 * the checkpoint timestamp
73 * the corresponding trace location
75 * the byte buffer to read from
77 public TmfCheckpoint(final ITmfTimestamp timestamp
, final ITmfLocation location
, ByteBuffer bufferIn
) {
78 fTimestamp
= timestamp
;
80 fCheckpointRank
= bufferIn
.getLong();
86 * @param other the other checkpoint
88 public TmfCheckpoint(final TmfCheckpoint other
) {
90 throw new IllegalArgumentException();
92 fTimestamp
= other
.fTimestamp
;
93 fLocation
= other
.fLocation
;
94 fCheckpointRank
= other
.fCheckpointRank
;
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
102 public ITmfTimestamp
getTimestamp() {
107 public ITmfLocation
getLocation() {
111 // ------------------------------------------------------------------------
113 // ------------------------------------------------------------------------
116 @SuppressWarnings({ "unchecked", "rawtypes" })
117 public int compareTo(final ITmfCheckpoint other
) {
119 if ((fTimestamp
!= null) && (other
.getTimestamp() != null)) {
120 comp
= fTimestamp
.compareTo(other
.getTimestamp());
124 // compare locations if timestamps are the same
127 if ((fLocation
== null) && (other
.getLocation() == null)) {
131 // treat location of other as null location which is before any location
132 if ((fLocation
!= null) && (other
.getLocation() == null)) {
136 // treat this as null location which is before any other locations
137 if ((fLocation
== null) && (other
.getLocation() != null)) {
142 final Comparable location1
= getLocation().getLocationInfo();
143 final Comparable location2
= other
.getLocation().getLocationInfo();
144 return location1
.compareTo(location2
);
147 // ------------------------------------------------------------------------
149 // ------------------------------------------------------------------------
152 public int hashCode() {
153 final int prime
= 31;
155 result
= prime
* result
+ ((fLocation
== null) ?
0 : fLocation
.hashCode());
156 result
= prime
* result
+ ((fTimestamp
== null) ?
0 : fTimestamp
.hashCode());
161 public boolean equals(final Object obj
) {
168 if (!(obj
instanceof TmfCheckpoint
)) {
171 final TmfCheckpoint other
= (TmfCheckpoint
) obj
;
172 if (fLocation
== null) {
173 if (other
.fLocation
!= null) {
176 } else if (!fLocation
.equals(other
.fLocation
)) {
179 if (fTimestamp
== null) {
180 if (other
.fTimestamp
!= null) {
183 } else if (!fTimestamp
.equals(other
.fTimestamp
)) {
190 @SuppressWarnings("nls")
191 public String
toString() {
192 return getClass().getSimpleName() + " [fLocation=" + fLocation
+ ", fTimestamp=" + fTimestamp
+ ", fCheckpointRank=" + fCheckpointRank
+ "]";
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
);
206 public long getCheckpointRank() {
207 return fCheckpointRank
;
This page took 0.037905 seconds and 5 git commands to generate.