import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
/**
if (events.get(event.getId()) != null) {
throw new ParseException("Event id already exists"); //$NON-NLS-1$
}
-
- /* Put the event in the map */
- events.put(event.getId(), event);
+ if (event.getId() == null) {
+ events.put(EventDeclaration.UNSET_EVENT_ID, event);
+ } else {
+ /* Put the event in the map */
+ events.put(event.getId(), event);
+ }
}
/**
*/
public class EventDeclaration implements IEventDeclaration {
+ /** Id of lost events */
+ public static final long LOST_EVENT_ID = -1L;
+
+ /** Id of events when not set */
+ public static final long UNSET_EVENT_ID = -2L;
+
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
/**
* Event id (can be null if only event in the stream).
*/
- private Long id = null;
+ private Long id = UNSET_EVENT_ID;
/**
* Stream to which belongs this event.
public static synchronized EventDeclaration getLostEventDeclaration() {
EventDeclaration lostEvent = new EventDeclaration();
lostEvent.fields = new StructDeclaration(1);
- lostEvent.id = -1L;
+ lostEvent.id = LOST_EVENT_ID;
lostEvent.name = "Lost event"; //$NON-NLS-1$
return lostEvent;
}
* @return is the id set?
*/
public boolean idIsSet() {
- return id != null;
+ return (id != null && id != UNSET_EVENT_ID);
}
/**
/**
* Gets the entries
+ *
* @return the entries
*/
public Vector<StreamInputPacketIndexEntry> getEntries() {
/**
* Gets an iterator to the entries
+ *
* @return an iterator to the entries
*/
public ListIterator<StreamInputPacketIndexEntry> listIterator() {
/**
* Gets an iterator to the entries at a given position
- * @param n the position to get
+ *
+ * @param n
+ * the position to get
* @return the iterator
*/
public ListIterator<StreamInputPacketIndexEntry> listIterator(int n) {
assert (entry.getContentSizeBits() != 0);
if (entry.getTimestampBegin() > entry.getTimestampEnd()) {
- throw new CTFReaderException(
- "Packet begin timestamp is after end timestamp"); //$NON-NLS-1$
+ throw new CTFReaderException("Packet begin timestamp is after end timestamp"); //$NON-NLS-1$
}
if (!this.entries.isEmpty()) {
if (entry.getTimestampBegin() < this.entries.lastElement()
.getTimestampBegin()) {
- throw new CTFReaderException(
- "Packets begin timestamp decreasing"); //$NON-NLS-1$
+ throw new CTFReaderException("Packets begin timestamp decreasing"); //$NON-NLS-1$
}
}
/*
* If the index is empty, return the iterator at the very beginning.
*/
- if( this.getEntries().isEmpty()) {
+ if (this.getEntries().isEmpty()) {
return this.getEntries().listIterator();
}
* the packet to return is before the guess.
*/
max = guessI - 1;
- } else if (timestamp >= guessEntry.getTimestampBegin()) {
+ } else if (timestamp > guessEntry.getTimestampBegin()) {
/*
* If the timestamp is after the begin timestamp, we know that
* the packet to return is after the guess or is the guess.
*/
min = guessI;
+ } else if (timestamp == guessEntry.getTimestampBegin()) {
+ /*
+ * If the timestamp is equal to the begin timestamp, we want to
+ * return the first packetIndexEntry that have this timestamp.
+ */
+ if (guessI > 0) {
+ StreamInputPacketIndexEntry previousGuessEntry = this.entries.get(guessI - 1);
+ while (guessI > 0 && guessEntry.getTimestampBegin() == previousGuessEntry.getTimestampBegin()) {
+ guessEntry = previousGuessEntry;
+ guessI--;
+ if (guessI - 1 >= 0) {
+ previousGuessEntry = this.entries.get(guessI - 1);
+ }
+ }
+ min = guessI;
+ max = guessI;
+ }
+
}
}