* 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;
*
*/
private void setUnknownLocation() {
- this.curLocation = nullLocation;
+ this.curLocation = NULL_LOCATION;
this.curRank = UNKNOWN_RANK;
}
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 {
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;
}
*/
@Override
public long getRank() {
- return super.getIndex();
+ return curRank;
}
/**
*/
@Override
public void setRank(final long rank) {
- if(!this.curLocation.equals(nullLocation)) {
- seekRank(rank);
- }
+ curRank = rank;
}
/*
*/
@Override
public void increaseRank() {
- curRank++;
+ /* Only increase the rank if it's valid */
+ if(hasValidRank()) {
+ curRank++;
+ }
}
/**
*/
@Override
public boolean advance() {
- return super.advance();
+ boolean ret = super.advance();
+ if (ret) {
+ curLocation.setLocation(getCurrentEvent().getTimestampValue());
+ } else {
+ curLocation = NULL_LOCATION;
+ }
+ return ret;
}
/**