Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / trace / TmfEventParserStub.java
index 1b739ca466a500757a3ebd90d7bf95f17902c20a..eab0891473a8abaebd56697eb45237f183bb1f7d 100644 (file)
@@ -19,51 +19,51 @@ import java.util.Vector;
 
 import org.eclipse.linuxtools.tmf.event.TmfEvent;
 import org.eclipse.linuxtools.tmf.event.TmfEventContent;
-import org.eclipse.linuxtools.tmf.event.TmfEventFormat;
 import org.eclipse.linuxtools.tmf.event.TmfEventReference;
 import org.eclipse.linuxtools.tmf.event.TmfEventSource;
 import org.eclipse.linuxtools.tmf.event.TmfEventType;
 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
 
 /**
  * <b><u>TmfEventParserStub</u></b>
  * <p>
  * TODO: Implement me. Please.
  */
+@SuppressWarnings("nls")
 public class TmfEventParserStub implements ITmfEventParser {
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Attributes
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
-       private final int NB_FORMATS = 10;
-    private final TmfEventFormat[] fFormats;
+       private final int NB_TYPES = 10;
+    private final TmfEventType[] fTypes;
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Constructors
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
     public TmfEventParserStub() {
-       fFormats = new TmfEventFormat[NB_FORMATS];
-       for (int i = 0; i < NB_FORMATS; i++) {
+       fTypes = new TmfEventType[NB_TYPES];
+       for (int i = 0; i < NB_TYPES; i++) {
                Vector<String> format = new Vector<String>();
                for (int j = 1; j <= i; j++) {
                        format.add(new String("Fmt-" + i + "-Fld-" + j));
                }
                String[] fields = new String[i];
-               fFormats[i] = new TmfEventFormat(format.toArray(fields));
+               fTypes[i] = new TmfEventType("Type-" + i, format.toArray(fields));
        }
     }
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Operators
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
-    /* (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent()
-     */
     static final String typePrefix = "Type-";
-    public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfTraceContext context) throws IOException {
+    @Override
+       @SuppressWarnings("unchecked")
+       public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfContext context) throws IOException {
 
         if (! (eventStream instanceof TmfTraceStub)) {
             return null;
@@ -74,48 +74,45 @@ public class TmfEventParserStub implements ITmfEventParser {
                String name = eventStream.getName();
                name = name.substring(name.lastIndexOf('/') + 1);
 
-        synchronized(stream) {
-               long location = 0;
-               if (context != null)
-                       location = (Long) (context.getLocation());
-               stream.seek(location);
-
-               try {
-                       long ts        = stream.readLong();
-                       String source  = stream.readUTF();
-                       String type    = stream.readUTF();
-                       @SuppressWarnings("unused")
-                       int reference  = stream.readInt();
-                       int typeIndex  = Integer.parseInt(type.substring(typePrefix.length()));
-                       String[] fields = new String[typeIndex];
-                       for (int i = 0; i < typeIndex; i++) {
-                               fields[i] = stream.readUTF();
-                       }
-
-                       // Update the context
-                       context.setLocation(stream.getFilePointer());
-                       context.incrIndex();
-
-                       String content = "[";
-                       if (typeIndex > 0) {
-                               content += fields[0];
-                       }
-                       for (int i = 1; i < typeIndex; i++) {
-                               content += ", " + fields[i];
-                       }
-                       content += "]";
-
-                       TmfEvent event = new TmfEvent(
-                                       new TmfTimestamp(ts, (byte) -3, 0),     // millisecs
-                                       new TmfEventSource(source),
-                                       new TmfEventType(type, fFormats[typeIndex]),
-                                       new TmfEventContent(content, fFormats[typeIndex]),
-                                       new TmfEventReference(name));
-                       return event;
-               } catch (EOFException e) {
-               }
-        }
+               // no need to use synchronized since it's already cover by the calling method
+               
+               long location = 0;
+               if (context != null)
+                   location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
+               stream.seek(location);
+
+               try {
+                   long ts        = stream.readLong();
+                   String source  = stream.readUTF();
+                   String type    = stream.readUTF();
+                   @SuppressWarnings("unused")
+                   int reference  = stream.readInt();
+                   int typeIndex  = Integer.parseInt(type.substring(typePrefix.length()));
+                   String[] fields = new String[typeIndex];
+                   for (int i = 0; i < typeIndex; i++) {
+                       fields[i] = stream.readUTF();
+                   }
+
+                   String content = "[";
+                   if (typeIndex > 0) {
+                       content += fields[0];
+                   }
+                   for (int i = 1; i < typeIndex; i++) {
+                       content += ", " + fields[i];
+                   }
+                   content += "]";
+
+                   TmfEvent event = new TmfEvent(
+                           new TmfTimestamp(ts, (byte) -3, 0),     // millisecs
+                           new TmfEventSource(source),
+                           fTypes[typeIndex],
+                           new TmfEventReference(name));
+                   TmfEventContent cnt = new TmfEventContent(event, content);
+                   event.setContent(cnt);
+                   return event;
+               } catch (EOFException e) {
+               }
         return null;
     }
 
-}
+}
\ No newline at end of file
This page took 0.038818 seconds and 5 git commands to generate.