Fix ranks in CtfTmfTrace as part of bug #389051
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfIterator.java
index 506e506e0a4a04f751e64c1436aab3750be8f319..2c2efbc1ea52fc37b5f23ff5ccb049b44e9ec885 100644 (file)
@@ -20,12 +20,11 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
  * it does not have a file handle, so many iterators can be used without worries
  * of io errors.
  */
-public class CtfIterator extends CTFTraceReader implements ITmfContext,
-        Comparable<CtfIterator> {
+public class CtfIterator extends CTFTraceReader implements ITmfContext, Comparable<CtfIterator>, Cloneable {
 
     private final CtfTmfTrace ctfTmfTrace;
 
-    final public static CtfLocation nullLocation = new CtfLocation(
+    final public static CtfLocation NULL_LOCATION = new CtfLocation(
             CtfLocation.INVALID_LOCATION);
     private CtfLocation curLocation;
     private long curRank;
@@ -52,7 +51,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      *
      */
     private void setUnknownLocation() {
-        this.curLocation = nullLocation;
+        this.curLocation = NULL_LOCATION;
         this.curRank = UNKNOWN_RANK;
     }
 
@@ -110,7 +109,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
     public boolean seek(final long timestamp) {
         boolean ret = false;
         final long offsetTimestamp = timestamp
-                - this.getCtfTmfTrace().getCTFTrace().getOffset();
+                - this.getTrace().getOffset();
         if (offsetTimestamp < 0) {
             ret = super.seek(timestamp);
         } else {
@@ -119,21 +118,8 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
         if (ret) {
             curLocation.setLocation(getCurrentEvent().getTimestampValue());
-        }
-        return ret;
-    }
-
-    /**
-     * Method seekRank. seeks to a given rank
-     * @param rank long the rank to seek to
-     * @return boolean
-     */
-    public boolean seekRank(final long rank) {
-        boolean ret = false;
-        ret = super.seekIndex(rank);
-
-        if (ret) {
-            curLocation.setLocation(getCurrentEvent().getTimestampValue());
+        } else {
+            curLocation = NULL_LOCATION;
         }
         return ret;
     }
@@ -145,7 +131,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      */
     @Override
     public long getRank() {
-        return super.getIndex();
+        return curRank;
     }
 
     /**
@@ -155,9 +141,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      */
     @Override
     public void setRank(final long rank) {
-        if(!this.curLocation.equals(nullLocation)) {
-            seekRank(rank);
-        }
+        curRank = rank;
     }
 
     /*
@@ -211,7 +195,10 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      */
     @Override
     public void increaseRank() {
-        curRank++;
+        /* Only increase the rank if it's valid */
+        if(hasValidRank()) {
+            curRank++;
+        }
     }
 
     /**
@@ -230,7 +217,13 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      */
     @Override
     public boolean advance() {
-        return super.advance();
+        boolean ret = super.advance();
+        if (ret) {
+            curLocation.setLocation(getCurrentEvent().getTimestampValue());
+        } else {
+            curLocation = NULL_LOCATION;
+        }
+        return ret;
     }
 
     /**
This page took 0.026783 seconds and 5 git commands to generate.