1 /*******************************************************************************
2 * Copyright (c) 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 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.core
.trace
.indexer
;
15 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.indexer
.checkpoint
.ITmfCheckpoint
;
18 * A visitor that searches for a specific checkpoint
20 * @author Marc-Andre Laperle
22 public class BTreeCheckpointVisitor
implements IBTreeVisitor
{
24 private long rank
= -1;
25 private ITmfCheckpoint found
;
26 private ITmfCheckpoint search
;
27 private boolean exactFound
= false;
30 * Constructs the checkpoint visitor
33 * the checkpoint to search for
35 public BTreeCheckpointVisitor(ITmfCheckpoint search
) {
40 public int compare(ITmfCheckpoint currentCheckpoint
) {
41 int compareTo
= currentCheckpoint
.compareTo(search
);
42 if (compareTo
<= 0 && !exactFound
) {
43 rank
= currentCheckpoint
.getCheckpointRank();
44 found
= currentCheckpoint
;
53 * Return the found checkpoint
55 * @return the found checkpoint
57 public ITmfCheckpoint
getCheckpoint() {
62 * Returns the checkpoint rank of the searched checkpoint, if it is
63 * contained in the index; otherwise, (-(insertion point) - 1).
65 * @return the checkpoint rank of the searched checkpoint, if it is
66 * contained in the index; otherwise, (-(insertion point) - 1).
68 public long getCheckpointRank() {
70 long insertionPoint
= rank
+ 1;
71 return -insertionPoint
- 1;