tmf: Clean up constructors in TmfTraceStub
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 30 Jul 2013 19:07:47 +0000 (15:07 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 5 Aug 2013 21:10:56 +0000 (17:10 -0400)
It also fixes some of those constructors not behaving as expected,
like having unused parameters and such.

Change-Id: I1aec63d90427ea43fd4e9edb3f9eb499e79488e2
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/14995
Tested-by: Hudson CI
12 files changed:
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedEventRequestTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfCheckpointIndexTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfCheckpointIndexTest2.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfExperimentCheckpointIndexTest.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfDataProviderStub.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfEventProviderStub.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java
org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/views/uml2sd/loader/Uml2SDTestFacility.java

index 5a22bc6b36e25cbbcf10b90c4c71a8ef89aebfed..2f83a2f727739a614cb162dab3d5a8757c760ad7 100644 (file)
@@ -96,7 +96,7 @@ public class TmfEventTest {
         try {
             final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
             final File test = new File(FileLocator.toFileURL(location).toURI());
-            trace = new TmfTraceStub(test.toURI().getPath(), 500, false);
+            trace = new TmfTraceStub(test.toURI().getPath(), 500, false, null, null);
         } catch (final TmfTraceException e) {
             e.printStackTrace();
         } catch (final URISyntaxException e) {
index 88e291f832723be88d4eac4e44e2c2efc084a45b..807117108992e006367dff0b095a0c1469b87ebc 100644 (file)
@@ -403,7 +403,7 @@ public class TmfCoalescedEventRequestTest {
             try {
                 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
                 File test = new File(FileLocator.toFileURL(location).toURI());
-                fTrace = new TmfTraceStub(test.getPath(), 500);
+                fTrace = new TmfTraceStub(test.getPath(), 500, false, null, null);
             } catch (TmfTraceException e) {
                 e.printStackTrace();
             } catch (URISyntaxException e) {
index 23e7327c8b55037851b6decc259ae16c08a7ab89..7f26716ff32ebd0e511cd1f493b069028c8913b7 100644 (file)
@@ -84,7 +84,7 @@ public class TmfExperimentTest {
             try {
                 final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
                 final File test = new File(FileLocator.toFileURL(location).toURI());
-                final TmfTraceStub trace = new TmfTraceStub(test.getPath(), 0, true);
+                final TmfTraceStub trace = new TmfTraceStub(test.getPath(), 0, true, null, null);
                 fTestTraces[0] = trace;
             } catch (final TmfTraceException e) {
                 e.printStackTrace();
index e497747249a178a8e4c47481d913156f734c9ea7..356fadb598eddf8961e38983cd4376dd2ab9af3a 100644 (file)
@@ -93,12 +93,12 @@ public class TmfMultiTraceExperimentTest {
 
             URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path1), null);
             File test = new File(FileLocator.toFileURL(location).toURI());
-            final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true);
+            final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true, null, null);
             traces[0] = trace1;
 
             location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path2), null);
             test = new File(FileLocator.toFileURL(location).toURI());
-            final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true);
+            final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true, null, null);
             traces[1] = trace2;
 
             return traces;
index 6547f0f6377c8cd2d48148ce9f3834c769d46e27..a0ea8694d5a095d0f8ad3850c1f673cb7225b881 100644 (file)
@@ -95,7 +95,7 @@ public class TmfTraceTest {
             try {
                 final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
                 final File test = new File(FileLocator.toFileURL(location).toURI());
-                fTrace = new TmfTraceStub(test.toURI().getPath());
+                fTrace = new TmfTraceStub(test.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null, null);
                 fTrace.indexTrace(true);
             } catch (final TmfTraceException e) {
                 e.printStackTrace();
@@ -120,7 +120,7 @@ public class TmfTraceTest {
         try {
             final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
             testfile = new File(FileLocator.toFileURL(location).toURI());
-            trace = new TmfTraceStub(testfile.toURI().getPath());
+            trace = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null, null);
             trace.indexTrace(true);
         } catch (final URISyntaxException e) {
             fail("URISyntaxException");
@@ -151,7 +151,7 @@ public class TmfTraceTest {
         try {
             final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
             testfile = new File(FileLocator.toFileURL(location).toURI());
-            trace = new TmfTraceStub(testfile.toURI().getPath(), 0);
+            trace = new TmfTraceStub(testfile.toURI().getPath(), 0, false, null, null);
             trace.indexTrace(true);
         } catch (final URISyntaxException e) {
             fail("URISyntaxException");
@@ -176,7 +176,7 @@ public class TmfTraceTest {
         try {
             final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
             testfile = new File(FileLocator.toFileURL(location).toURI());
-            trace = new TmfTraceStub(testfile.toURI().getPath());
+            trace = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null, null);
             trace.indexTrace(true);
         } catch (final URISyntaxException e) {
             fail("URISyntaxException");
@@ -205,7 +205,7 @@ public class TmfTraceTest {
         try {
             final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
             testfile = new File(FileLocator.toFileURL(location).toURI());
-            trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, null);
+            trace = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, false, null, null);
             trace.indexTrace(true);
         } catch (final URISyntaxException e) {
             fail("URISyntaxException");
@@ -267,7 +267,7 @@ public class TmfTraceTest {
         try {
             final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
             testfile = new File(FileLocator.toFileURL(location).toURI());
-            original = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, new TmfCheckpointIndexer(null));
+            original = new TmfTraceStub(testfile.toURI().getPath(), BLOCK_SIZE, false, new TmfCheckpointIndexer(null), null);
             trace = new TmfTraceStub(original);
             trace.indexTrace(true);
         } catch (final URISyntaxException e) {
@@ -1451,7 +1451,7 @@ public class TmfTraceTest {
         try {
             final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
             testfile = new File(FileLocator.toFileURL(location).toURI());
-            trace = new TmfTraceStub(testfile.toURI().getPath());
+            trace = new TmfTraceStub(testfile.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null, null);
             // verify initial values
             TmfTimestamp defaultInitRange = new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE);
             assertEquals("getInitialRangeOffset", defaultInitRange, trace.getInitialRangeOffset());
index 1cd80db10354a2e2d18d3ada16ab74633ce5c954..9ff489823109bf487cc6b783eee205dd428383cb 100644 (file)
@@ -93,7 +93,7 @@ public class TmfCheckpointIndexTest {
 
     private class TestTrace extends TmfTraceStub {
         public TestTrace(String path, int blockSize) throws TmfTraceException {
-            super(path, blockSize);
+            super(path, blockSize, false, null, null);
             setIndexer(new TestIndexer(this));
         }
         @Override
index 4d1460339e738eb36369846c4dab22aa07e02ae0..2e5c2f6463171c03e81a9ff54f30670718750e3e 100644 (file)
@@ -95,7 +95,7 @@ public class TmfCheckpointIndexTest2 {
 
     private class TestTrace extends TmfTraceStub {
         public TestTrace(String path, int blockSize) throws TmfTraceException {
-            super(path, blockSize);
+            super(path, blockSize, false, null, null);
             setIndexer(new TestIndexer(this));
         }
         @Override
index 3352aea5b9e80660c68a1b5a19883f85d4999159..e02aa7e8bae290af6b5baa7a5d06fc75a374ffad 100644 (file)
@@ -89,11 +89,11 @@ public class TmfExperimentCheckpointIndexTest {
         try {
             URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path1), null);
             File test = new File(FileLocator.toFileURL(location).toURI());
-            final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true);
+            final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true, null, null);
             fTestTraces[0] = trace1;
             location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path2), null);
             test = new File(FileLocator.toFileURL(location).toURI());
-            final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true);
+            final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true, null, null);
             fTestTraces[1] = trace2;
         } catch (final TmfTraceException e) {
             e.printStackTrace();
@@ -143,11 +143,11 @@ public class TmfExperimentCheckpointIndexTest {
         try {
             URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM1), null);
             File test = new File(FileLocator.toFileURL(location).toURI());
-            final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, false);
+            final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, false, null, null);
             testTraces[0] = trace1;
             location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM2), null);
             test = new File(FileLocator.toFileURL(location).toURI());
-            final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, false);
+            final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, false, null, null);
             testTraces[1] = trace2;
         } catch (final TmfTraceException e) {
             e.printStackTrace();
index db9304c146f8a6f5d1140c87da148096be49d7b6..bb264f5e2e6244f36c2b3da4ec668d366e7b2ea0 100644 (file)
@@ -46,7 +46,7 @@ public class TmfDataProviderStub extends TmfDataProvider {
         final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
         try {
             final File test = new File(FileLocator.toFileURL(location).toURI());
-            fTrace = new TmfTraceStub(test.getPath(), 0, true);
+            fTrace = new TmfTraceStub(test.getPath(), 0, true, null, null);
         } catch (final TmfTraceException e) {
             e.printStackTrace();
         } catch (final URISyntaxException e) {
index bbcee8a8a94bdeb0a3d877ec07d02a9db893235b..2728caf1bb90e69b0c4d305218095afdf556c372 100644 (file)
@@ -46,7 +46,7 @@ public class TmfEventProviderStub extends TmfEventProvider {
         final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
         try {
             final File test = new File(FileLocator.toFileURL(location).toURI());
-            fTrace = new TmfTraceStub(test.getPath(), 0, true);
+            fTrace = new TmfTraceStub(test.getPath(), 0, true, null, null);
         } catch (final TmfTraceException e) {
             e.printStackTrace();
         } catch (final URISyntaxException e) {
index 8b7b430fcad9445a34a68439a19afdc76316abf8..8eadfd7266143002b390a6e1bbb575dac5bc9bdf 100644 (file)
@@ -29,7 +29,6 @@ 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.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
@@ -41,7 +40,6 @@ import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
  * <p>
  * Dummy test trace. Use in conjunction with TmfEventParserStub.
  */
-@SuppressWarnings("javadoc")
 public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
 
     // ------------------------------------------------------------------------
@@ -63,126 +61,92 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
     // Constructors
     // ------------------------------------------------------------------------
 
+    /**
+     * Default constructor
+     */
     public TmfTraceStub() {
         super();
         setParser(new TmfEventParserStub(this));
     }
 
     /**
+     * Constructor with which you can specify a custom streaming interval. The
+     * parser and indexer won't be specified.
+     *
      * @param path
-     * @throws FileNotFoundException
-     */
-    public TmfTraceStub(final String path) throws TmfTraceException {
-        this(path, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false);
-    }
-
-    /**
-     * @param path
+     *            The path to the trace file
      * @param cacheSize
-     * @throws FileNotFoundException
+     *            The cache size
+     * @param interval
+     *            The trace streaming interval
+     * @throws TmfTraceException
+     *             If an error occurred opening the trace
      */
-    public TmfTraceStub(final String path, final int cacheSize) throws TmfTraceException {
-        this(path, cacheSize, false);
-    }
-
-    /**
-     * @param path
-     * @param cacheSize
-     * @throws FileNotFoundException
-     */
-    public TmfTraceStub(final String path, final int cacheSize, final long interval) throws TmfTraceException {
+    public TmfTraceStub(final String path,
+            final int cacheSize,
+            final long interval) throws TmfTraceException {
         super(null, ITmfEvent.class, path, cacheSize, interval, null, null);
-        try {
-            fTrace = new RandomAccessFile(path, "r"); //$NON-NLS-1$
-        } catch (FileNotFoundException e) {
-            throw new TmfTraceException(e.getMessage());
-        }
+        setupTrace(path);
         setParser(new TmfEventParserStub(this));
     }
 
     /**
+     * Constructor to specify the parser and indexer. The streaming interval
+     * will be 0.
+     *
      * @param path
+     *            The path to the trace file
      * @param cacheSize
-     * @throws FileNotFoundException
-     */
-    public TmfTraceStub(final String path, final int cacheSize, final ITmfTraceIndexer indexer) throws TmfTraceException {
-        this(path, cacheSize, false, null, indexer);
-    }
-
-    /**
-     * @param path
-     * @param waitForCompletion
-     * @throws FileNotFoundException
-     */
-    public TmfTraceStub(final String path, final boolean waitForCompletion) throws TmfTraceException {
-        this(path, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, waitForCompletion);
-    }
-
-    /**
-     * @param path
-     * @param cacheSize
+     *            The cache size
      * @param waitForCompletion
-     * @throws FileNotFoundException
+     *            Do we block the caller until the trace is indexed, or not.
+     * @param indexer
+     *            The trace indexer to use
+     * @param parser
+     *            The trace parser. If left 'null', it will use a
+     *            {@link TmfEventParserStub}.
+     * @throws TmfTraceException
+     *             If an error occurred opening the trace
      */
-    public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion) throws TmfTraceException {
-        super(null, ITmfEvent.class, path, cacheSize, 0, null, null);
-        try {
-            fTrace = new RandomAccessFile(path, "r"); //$NON-NLS-1$
-        } catch (FileNotFoundException e) {
-            throw new TmfTraceException(e.getMessage());
-        }
-        setParser(new TmfEventParserStub(this));
+    public TmfTraceStub(final String path,
+            final int cacheSize,
+            final boolean waitForCompletion,
+            final ITmfTraceIndexer indexer,
+            final ITmfEventParser parser) throws TmfTraceException {
+        super(null, ITmfEvent.class, path, cacheSize, 0, indexer, null);
+        setupTrace(path);
+        setParser((parser != null) ? parser : new TmfEventParserStub(this));
         if (waitForCompletion) {
             indexTrace(true);
         }
     }
 
     /**
-     * @param path
-     * @param cacheSize
-     * @param waitForCompletion
-     * @throws FileNotFoundException
+     * Copy constructor
+     *
+     * @param trace
+     *            The trace to copy
+     * @throws TmfTraceException
+     *             If an error occurred opening the trace
      */
-    public TmfTraceStub(final IResource resource,  final String path, final int cacheSize, final boolean waitForCompletion) throws TmfTraceException {
-        super(resource, ITmfEvent.class, path, cacheSize, 0, null, null);
-        try {
-            fTrace = new RandomAccessFile(path, "r"); //$NON-NLS-1$
-        } catch (FileNotFoundException e) {
-            throw new TmfTraceException(e.getMessage());
-        }
+    public TmfTraceStub(final TmfTraceStub trace) throws TmfTraceException {
+        super(trace);
+        setupTrace(getPath()); // fPath will be set by the super-constructor
         setParser(new TmfEventParserStub(this));
     }
 
-    /**
-     * @param path
-     * @param cacheSize
-     * @param waitForCompletion
-     * @param parser
-     * @throws FileNotFoundException
-     */
-    public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion,
-            final ITmfEventParser parser, final ITmfTraceIndexer indexer) throws TmfTraceException {
-        super(null, ITmfEvent.class, path, cacheSize, 0, indexer, null);
+
+    private void setupTrace(String path) throws TmfTraceException {
         try {
             fTrace = new RandomAccessFile(path, "r"); //$NON-NLS-1$
         } catch (FileNotFoundException e) {
             throw new TmfTraceException(e.getMessage());
         }
-        setParser((parser != null) ? parser : new TmfEventParserStub(this));
     }
 
-    /**
-     * Copy constructor
-     */
-    public TmfTraceStub(final TmfTraceStub trace) throws TmfTraceException {
-        super(trace);
-        try {
-            fTrace = new RandomAccessFile(getPath(), "r"); //$NON-NLS-1$
-        } catch (FileNotFoundException e) {
-            throw new TmfTraceException(e.getMessage());
-        }
-        setParser(new TmfEventParserStub(this));
-    }
+    // ------------------------------------------------------------------------
+    // Initializers
+    // ------------------------------------------------------------------------
 
     @Override
     public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
@@ -204,10 +168,19 @@ public class TmfTraceStub extends TmfTrace implements ITmfEventParser {
     // Accessors
     // ------------------------------------------------------------------------
 
+    /**
+     * @return The file stream to the trace
+     */
     public RandomAccessFile getStream() {
         return fTrace;
     }
 
+    /**
+     * Set the initial range offset.
+     *
+     * @param initOffset
+     *            The new initial range offset
+     */
     public void setInitialRangeOffset(ITmfTimestamp initOffset) {
         fInitialRangeOffset = initOffset;
     }
index 5f460642d2a5ca1cd7575e0735d54569bb0b038d..c342ae95e69a7b82000f707be1aca6345a6b9f0e 100644 (file)
@@ -134,7 +134,7 @@ public class Uml2SDTestFacility {
             // Create test trace object
             final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null);
             final File test = new File(FileLocator.toFileURL(location).toURI());
-            return new TmfTraceStub(test.getPath(), 500, true, parser, null);
+            return new TmfTraceStub(test.getPath(), 500, true, null, parser);
         } catch (final TmfTraceException e) {
             e.printStackTrace();
             throw new RuntimeException(e);
This page took 0.047516 seconds and 5 git commands to generate.