Refactor TmfTrace and dependencies - move parseEvent to ITmfEventParser
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / stubs / org / eclipse / linuxtools / tmf / tests / stubs / trace / TmfTraceStub.java
index c9d032d4e6780cce4848d9bf057646a08a00036d..69d3a87424e81ad84504ace5d4e28437677af46d 100644 (file)
@@ -22,8 +22,8 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.parser.ITmfEventParser;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceIndexer;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
@@ -36,7 +36,7 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
  * Dummy test trace. Use in conjunction with TmfEventParserStub.
  */
 @SuppressWarnings("nls")
-public class TmfTraceStub extends TmfTrace<TmfEvent> {
+public class TmfTraceStub extends TmfTrace<TmfEvent> implements ITmfEventParser<TmfEvent> {
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -45,8 +45,8 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
     // The actual stream
     private RandomAccessFile fTrace;
 
-    // The associated event parser
-    private ITmfEventParser<TmfEvent> fParser;
+//    // The associated event parser
+//    private ITmfEventParser<TmfEvent> fParser;
 
     // The synchronization lock
     private final ReentrantLock fLock = new ReentrantLock();
@@ -61,7 +61,7 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
      */
     public TmfTraceStub() {
         super();
-        fParser = new TmfEventParserStub();
+        fParser = new TmfEventParserStub(this);
     }
 
     /**
@@ -89,7 +89,7 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
     public TmfTraceStub(final String path, final int cacheSize, final long interval) throws FileNotFoundException {
         super(null, TmfEvent.class, path, cacheSize, interval);
         fTrace = new RandomAccessFile(path, "r");
-        fParser = new TmfEventParserStub();
+        fParser = new TmfEventParserStub(this);
     }
 
     /**
@@ -119,7 +119,7 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
     public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion) throws FileNotFoundException {
         super(null, TmfEvent.class, path, cacheSize);
         fTrace = new RandomAccessFile(path, "r");
-        fParser = new TmfEventParserStub();
+        fParser = new TmfEventParserStub(this);
     }
 
     /**
@@ -131,7 +131,7 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
     public TmfTraceStub(final IResource resource,  final String path, final int cacheSize, final boolean waitForCompletion) throws FileNotFoundException {
         super(resource, TmfEvent.class, path, cacheSize);
         fTrace = new RandomAccessFile(path, "r");
-        fParser = new TmfEventParserStub();
+        fParser = new TmfEventParserStub(this);
     }
 
     /**
@@ -141,11 +141,12 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
      * @param parser
      * @throws FileNotFoundException
      */
+    @SuppressWarnings("unchecked")
     public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion,
             final ITmfEventParser<TmfEvent> parser, final ITmfTraceIndexer<?> indexer) throws FileNotFoundException {
         super(null, TmfEvent.class, path, cacheSize, 0, indexer);
         fTrace = new RandomAccessFile(path, "r");
-        fParser = (parser != null) ? parser : new TmfEventParserStub();
+        fParser = (ITmfEventParser<ITmfEvent>) ((parser != null) ? parser : new TmfEventParserStub(this));
     }
 
     /**
@@ -154,7 +155,7 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
     public TmfTraceStub(final TmfTraceStub trace) throws FileNotFoundException {
         super(trace);
         fTrace = new RandomAccessFile(getPath(), "r");
-        fParser = new TmfEventParserStub();
+        fParser = new TmfEventParserStub(this);
     }
 
     public void indexTrace() {
@@ -164,7 +165,7 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
     @Override
     public void initTrace(final IResource resource, final String path, final Class<TmfEvent> type) throws FileNotFoundException {
         fTrace = new RandomAccessFile(path, "r");
-        fParser = new TmfEventParserStub();
+        fParser = new TmfEventParserStub(this);
         super.initTrace(resource, path, type);
     }
 
@@ -187,7 +188,7 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
 
     @Override
     @SuppressWarnings("unchecked")
-    public TmfContext seekLocation(final ITmfLocation<?> location) {
+    public TmfContext seekEvent(final ITmfLocation<?> location) {
         try {
             fLock.lock();
             try {
@@ -222,12 +223,12 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
 
 
     @Override
-    public TmfContext seekLocation(final double ratio) {
+    public TmfContext seekEvent(final double ratio) {
         fLock.lock();
         try {
             if (fTrace != null) {
                 final ITmfLocation<?> location = new TmfLocation<Long>(Long.valueOf((long) (ratio * fTrace.length())));
-                final TmfContext context = seekLocation(location);
+                final TmfContext context = seekEvent(location);
                 context.setRank(ITmfContext.UNKNOWN_RANK);
                 return context;
             }
@@ -276,12 +277,12 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
         try {
             // parseNextEvent will update the context
             if (fTrace != null) {
-                final ITmfEvent event = fParser.parseNextEvent(this, context.clone());
+                final ITmfEvent event = fParser.parseEvent(context.clone());
                 return event;
             }
-        }
-        catch (final IOException e) {
-            e.printStackTrace();
+//        }
+//        catch (final IOException e) {
+//            e.printStackTrace();
         } finally {
             fLock.unlock();
         }
This page took 0.026661 seconds and 5 git commands to generate.