Refactor TmfExperiment
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfCheckpointIndexer.java
index aaedb788d0d67bd6677015214aa221e0d716b16f..49b2bf9e81f31f770af8bdef137660774b58ba20 100644 (file)
@@ -12,8 +12,9 @@
 
 package org.eclipse.linuxtools.tmf.core.trace;
 
+import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Vector;
+import java.util.List;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
@@ -41,11 +42,9 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
  * Locating a specific checkpoint is trivial for both rank (rank % interval) and
  * timestamp (bsearch in the array).
  * 
- * @since 1.0
  * @version 1.0
  * @author Francois Chouinard
  *
- * @see ITmfTraceIndexer
  * @see ITmfTrace
  * @see ITmfEvent
  */
@@ -55,21 +54,17 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm
     // Attributes
     // ------------------------------------------------------------------------
 
-    /**
-     * The event trace to index
-     */
+    // The event trace to index
     private final ITmfTrace<ITmfEvent> fTrace;
 
-    /**
-     * The interval between checkpoints
-     */
-    protected final int fCheckpointInterval;
+    // The interval between checkpoints
+    private final int fCheckpointInterval;
 
     /**
      * The trace index. It is composed of checkpoints taken at intervals of
      * fCheckpointInterval events.
      */
-    protected final Vector<TmfCheckpoint> fTraceIndex;
+    private final List<TmfCheckpoint> fTraceIndex;
 
     // ------------------------------------------------------------------------
     // Construction
@@ -94,7 +89,7 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm
     public TmfCheckpointIndexer(final ITmfTrace<ITmfEvent> trace, final int interval) {
         fTrace = trace;
         fCheckpointInterval = interval;
-        fTraceIndex = new Vector<TmfCheckpoint>();
+        fTraceIndex = new ArrayList<TmfCheckpoint>();
     }
 
     // ------------------------------------------------------------------------
@@ -138,8 +133,8 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm
         final ITmfEventRequest<ITmfEvent> request = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, TmfTimeRange.ETERNITY,
                 TmfDataRequest.ALL_DATA, fCheckpointInterval, ITmfDataRequest.ExecutionType.BACKGROUND)
         {
-            ITmfTimestamp startTime = null;
-            ITmfTimestamp lastTime = null;
+            private ITmfTimestamp startTime = null;
+            private ITmfTimestamp lastTime = null;
 
             @Override
             public void handleData(final ITmfEvent event) {
@@ -228,8 +223,9 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm
     public synchronized ITmfContext seekIndex(final ITmfTimestamp timestamp) {
 
         // A null timestamp indicates to seek the first event
-        if (timestamp == null)
+        if (timestamp == null) {
             return fTrace.seekEvent(0);
+        }
 
         // Find the checkpoint at or before the requested timestamp.
         // In the very likely event that the timestamp is not at a checkpoint
@@ -251,8 +247,9 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm
     public ITmfContext seekIndex(final long rank) {
 
       // A rank < 0 indicates to seek the first event
-      if (rank < 0)
+      if (rank < 0) {
           return fTrace.seekEvent(0);
+      }
 
       // Find the checkpoint at or before the requested rank.
       final int index = (int) rank / fCheckpointInterval;
@@ -264,18 +261,18 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm
     /**
      * Position the trace at the given checkpoint
      * 
-     * @param index
-     *            the checkpoint index
+     * @param checkpoint the checkpoint index
      * @return the corresponding context
      */
-    private ITmfContext seekCheckpoint(int index) {
+    private ITmfContext seekCheckpoint(final int checkpoint) {
         ITmfLocation<?> location;
+        int index = checkpoint;
         synchronized (fTraceIndex) {
             if (!fTraceIndex.isEmpty()) {
                 if (index >= fTraceIndex.size()) {
                     index = fTraceIndex.size() - 1;
                 }
-                location = fTraceIndex.elementAt(index).getLocation();
+                location = fTraceIndex.get(index).getLocation();
             } else {
                 location = null;
             }
@@ -285,4 +282,14 @@ public class TmfCheckpointIndexer<T extends ITmfTrace<ITmfEvent>> implements ITm
         return context;
     }
 
+    // ------------------------------------------------------------------------
+    // Getters
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the trace index
+     */
+    protected List<TmfCheckpoint> getTraceIndex() {
+        return fTraceIndex;
+    }
 }
This page took 0.025444 seconds and 5 git commands to generate.