1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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
.linuxtools
.tmf
.core
.trace
.indexer
.checkpoint
;
17 import java
.nio
.ByteBuffer
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
21 import org
.eclipse
.linuxtools
.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
33 public class TmfCheckpoint
implements ITmfCheckpoint
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 // The checkpoint location
40 private final ITmfLocation fLocation
;
42 // The checkpoint timestamp
43 private final ITmfTimestamp fTimestamp
;
45 private final long fCheckpointRank
;
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
55 * the checkpoint timestamp
57 * the corresponding trace location
58 * @param checkpointRank
59 * the rank of the checkpoint
62 public TmfCheckpoint(final ITmfTimestamp timestamp
, final ITmfLocation location
, long checkpointRank
) {
63 fTimestamp
= timestamp
;
65 fCheckpointRank
= checkpointRank
;
69 * Constructs a checkpoint using also a byte buffer to read the rank from
73 * the checkpoint timestamp
75 * the corresponding trace location
77 * the byte buffer to read from
81 public TmfCheckpoint(final ITmfTimestamp timestamp
, final ITmfLocation location
, ByteBuffer bufferIn
) {
82 fTimestamp
= timestamp
;
84 fCheckpointRank
= bufferIn
.getLong();
90 * @param other the other checkpoint
92 public TmfCheckpoint(final TmfCheckpoint other
) {
94 throw new IllegalArgumentException();
96 fTimestamp
= other
.fTimestamp
;
97 fLocation
= other
.fLocation
;
98 fCheckpointRank
= other
.fCheckpointRank
;
101 // ------------------------------------------------------------------------
103 // ------------------------------------------------------------------------
109 public ITmfTimestamp
getTimestamp() {
114 public ITmfLocation
getLocation() {
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
123 @SuppressWarnings({ "unchecked", "rawtypes" })
124 public int compareTo(final ITmfCheckpoint other
) {
126 if ((fTimestamp
!= null) && (other
.getTimestamp() != null)) {
127 comp
= fTimestamp
.compareTo(other
.getTimestamp(), false);
131 // compare locations if timestamps are the same
134 if ((fLocation
== null) && (other
.getLocation() == null)) {
138 // treat location of other as null location which is before any location
139 if ((fLocation
!= null) && (other
.getLocation() == null)) {
143 // treat this as null location which is before any other locations
144 if ((fLocation
== null) && (other
.getLocation() != null)) {
149 final Comparable location1
= getLocation().getLocationInfo();
150 final Comparable location2
= other
.getLocation().getLocationInfo();
151 return location1
.compareTo(location2
);
154 // ------------------------------------------------------------------------
156 // ------------------------------------------------------------------------
159 public int hashCode() {
160 final int prime
= 31;
162 result
= prime
* result
+ ((fLocation
== null) ?
0 : fLocation
.hashCode());
163 result
= prime
* result
+ ((fTimestamp
== null) ?
0 : fTimestamp
.hashCode());
168 public boolean equals(final Object obj
) {
175 if (!(obj
instanceof TmfCheckpoint
)) {
178 final TmfCheckpoint other
= (TmfCheckpoint
) obj
;
179 if (fLocation
== null) {
180 if (other
.fLocation
!= null) {
183 } else if (!fLocation
.equals(other
.fLocation
)) {
186 if (fTimestamp
== null) {
187 if (other
.fTimestamp
!= null) {
190 } else if (!fTimestamp
.equals(other
.fTimestamp
)) {
197 @SuppressWarnings("nls")
198 public String
toString() {
199 return getClass().getSimpleName() + " [fLocation=" + fLocation
+ ", fTimestamp=" + fTimestamp
+ ", fCheckpointRank=" + fCheckpointRank
+ "]";
206 public void serialize(ByteBuffer bufferOut
) {
207 fLocation
.serialize(bufferOut
);
208 // Always serialize as base TmfTimestamp, this should be sufficient for indexing.
209 // If not, we can add API for the test to restore the time stamp, similarly to the location.
210 TmfTimestamp t
= new TmfTimestamp(fTimestamp
);
211 t
.serialize(bufferOut
);
212 bufferOut
.putLong(fCheckpointRank
);
219 public long getCheckpointRank() {
220 return fCheckpointRank
;
This page took 0.038229 seconds and 6 git commands to generate.