tmf: Clean up tmf.core.trace package
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / stubs / org / eclipse / linuxtools / tmf / tests / stubs / trace / TmfTraceStub.java
index 87b97f34897f51c85bdfdf75a108ad1399c6b363..8b7b430fcad9445a34a68439a19afdc76316abf8 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * Copyright (c) 2009, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Patrick Tasse - Updated for removal of context clone
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.tests.stubs.trace;
@@ -19,26 +20,28 @@ import java.util.concurrent.locks.ReentrantLock;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.internal.tmf.core.Activator;
 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.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 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.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceIndexer;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
 
 /**
  * <b><u>TmfTraceStub</u></b>
  * <p>
  * Dummy test trace. Use in conjunction with TmfEventParserStub.
  */
-@SuppressWarnings({"nls","javadoc"})
+@SuppressWarnings("javadoc")
 public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
 
     // ------------------------------------------------------------------------
@@ -54,6 +57,8 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
     // The synchronization lock
     private final ReentrantLock fLock = new ReentrantLock();
 
+    private ITmfTimestamp fInitialRangeOffset = null;
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -86,9 +91,9 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
      * @throws FileNotFoundException
      */
     public TmfTraceStub(final String path, final int cacheSize, final long interval) throws TmfTraceException {
-        super(null, TmfEvent.class, path, cacheSize, interval);
+        super(null, ITmfEvent.class, path, cacheSize, interval, null, null);
         try {
-            fTrace = new RandomAccessFile(path, "r");
+            fTrace = new RandomAccessFile(path, "r"); //$NON-NLS-1$
         } catch (FileNotFoundException e) {
             throw new TmfTraceException(e.getMessage());
         }
@@ -120,15 +125,15 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
      * @throws FileNotFoundException
      */
     public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion) throws TmfTraceException {
-        super(null, TmfEvent.class, path, cacheSize);
+        super(null, ITmfEvent.class, path, cacheSize, 0, null, null);
         try {
-            fTrace = new RandomAccessFile(path, "r");
+            fTrace = new RandomAccessFile(path, "r"); //$NON-NLS-1$
         } catch (FileNotFoundException e) {
             throw new TmfTraceException(e.getMessage());
         }
         setParser(new TmfEventParserStub(this));
         if (waitForCompletion) {
-            indexTrace();
+            indexTrace(true);
         }
     }
 
@@ -139,9 +144,9 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
      * @throws FileNotFoundException
      */
     public TmfTraceStub(final IResource resource,  final String path, final int cacheSize, final boolean waitForCompletion) throws TmfTraceException {
-        super(resource, TmfEvent.class, path, cacheSize);
+        super(resource, ITmfEvent.class, path, cacheSize, 0, null, null);
         try {
-            fTrace = new RandomAccessFile(path, "r");
+            fTrace = new RandomAccessFile(path, "r"); //$NON-NLS-1$
         } catch (FileNotFoundException e) {
             throw new TmfTraceException(e.getMessage());
         }
@@ -157,9 +162,9 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
      */
     public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion,
             final ITmfEventParser parser, final ITmfTraceIndexer indexer) throws TmfTraceException {
-        super(null, TmfEvent.class, path, cacheSize, 0, indexer);
+        super(null, ITmfEvent.class, path, cacheSize, 0, indexer, null);
         try {
-            fTrace = new RandomAccessFile(path, "r");
+            fTrace = new RandomAccessFile(path, "r"); //$NON-NLS-1$
         } catch (FileNotFoundException e) {
             throw new TmfTraceException(e.getMessage());
         }
@@ -172,21 +177,17 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
     public TmfTraceStub(final TmfTraceStub trace) throws TmfTraceException {
         super(trace);
         try {
-            fTrace = new RandomAccessFile(getPath(), "r");
+            fTrace = new RandomAccessFile(getPath(), "r"); //$NON-NLS-1$
         } catch (FileNotFoundException e) {
             throw new TmfTraceException(e.getMessage());
         }
         setParser(new TmfEventParserStub(this));
     }
 
-    public void indexTrace() {
-        indexTrace(true);
-    }
-
     @Override
     public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
         try {
-            fTrace = new RandomAccessFile(path, "r");
+            fTrace = new RandomAccessFile(path, "r"); //$NON-NLS-1$
         } catch (FileNotFoundException e) {
             throw new TmfTraceException(e.getMessage());
         }
@@ -207,13 +208,24 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
         return fTrace;
     }
 
+    public void setInitialRangeOffset(ITmfTimestamp initOffset) {
+        fInitialRangeOffset = initOffset;
+    }
+
+    @Override
+    public ITmfTimestamp getInitialRangeOffset() {
+        if (fInitialRangeOffset != null) {
+            return fInitialRangeOffset;
+        }
+        return super.getInitialRangeOffset();
+    }
+
     // ------------------------------------------------------------------------
     // Operators
     // ------------------------------------------------------------------------
 
     @Override
-    @SuppressWarnings("unchecked")
-    public TmfContext seekEvent(final ITmfLocation<?> location) {
+    public TmfContext seekEvent(final ITmfLocation location) {
         try {
             fLock.lock();
             try {
@@ -223,7 +235,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
                     long loc  = 0;
                     long rank = 0;
                     if (location != null) {
-                        loc = ((ITmfLocation<Long>) location).getLocationData();
+                        loc = (Long) location.getLocationInfo();
                         rank = ITmfContext.UNKNOWN_RANK;
                     }
                     if (loc != fTrace.getFilePointer()) {
@@ -252,7 +264,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
         fLock.lock();
         try {
             if (fTrace != null) {
-                final ITmfLocation<?> location = new TmfLongLocation(Long.valueOf((long) (ratio * fTrace.length())));
+                final ITmfLocation location = new TmfLongLocation(Long.valueOf(Math.round(ratio * fTrace.length())));
                 final TmfContext context = seekEvent(location);
                 context.setRank(ITmfContext.UNKNOWN_RANK);
                 return context;
@@ -267,12 +279,12 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
     }
 
     @Override
-    public double getLocationRatio(ITmfLocation<?> location) {
+    public double getLocationRatio(ITmfLocation location) {
         fLock.lock();
         try {
             if (fTrace != null) {
-                if (location.getLocationData() instanceof Long) {
-                    return (double) ((Long) location.getLocationData()) / fTrace.length();
+                if (location.getLocationInfo() instanceof Long) {
+                    return (double) ((Long) location.getLocationInfo()) / fTrace.length();
                 }
             }
         } catch (final IOException e) {
@@ -284,7 +296,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
     }
 
     @Override
-    public ITmfLocation<Long> getCurrentLocation() {
+    public ITmfLocation getCurrentLocation() {
         fLock.lock();
         try {
             if (fTrace != null) {
@@ -304,7 +316,7 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
         try {
             // parseNextEvent will update the context
             if (fTrace != null && getParser() != null && context != null) {
-                final ITmfEvent event = getParser().parseEvent(context.clone());
+                final ITmfEvent event = getParser().parseEvent(context);
                 return event;
             }
         } finally {
@@ -354,12 +366,12 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
         super.dispose();
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)
-     */
     @Override
-    public boolean validate(IProject project, String path) {
-        return fileExists(path);
+    public IStatus validate(IProject project, String path) {
+        if (fileExists(path)) {
+            return Status.OK_STATUS;
+        }
+        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "File does not exist: " + path);
     }
 
 }
This page took 0.027999 seconds and 5 git commands to generate.