tmf: Clean up tmf.core.trace package
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 17 Jul 2013 21:33:35 +0000 (17:33 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 5 Aug 2013 21:10:35 +0000 (17:10 -0400)
Move some notions out of this packages and into their own:
- tmf.core.trace.indexer (for the ITmfTraceIndexer interface)
- tmf.core.trace.indexer.checkpoint (for the checkpoint indexer)
- tmf.core.trace.location (for ITmfLocation and its gang)

This will prepare the grounds for the upcoming on-disk B-tree indexer.

Change-Id: I48bee4b30ddd17d32f4d7373e6391c248a9687e9
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/14634
Tested-by: Hudson CI
58 files changed:
org.eclipse.linuxtools.gdbtrace.core/src/org/eclipse/linuxtools/internal/gdbtrace/core/trace/GdbTrace.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/AllTmfCoreTests.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java [deleted file]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest2.java [deleted file]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java [deleted file]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentCheckpointIndexTest.java [deleted file]
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/TmfLocationTest.java [deleted file]
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/TmfStringLocation.java [deleted file]
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/AllTests.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfCheckpointIndexTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfCheckpointIndexTest2.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfCheckpointTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfExperimentCheckpointIndexTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/location/AllTests.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/location/TmfLocationTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/location/TmfStringLocation.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfEmptyTraceStub.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfIndexerStub.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java
org.eclipse.linuxtools.tmf.core/META-INF/MANIFEST.MF
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfExperimentLocation.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/trace/TmfLocationArray.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContext.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfCheckpoint.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfContext.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceIndexer.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfContext.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfExperiment.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLongLocation.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTimestampLocation.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/ITmfTraceIndexer.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/checkpoint/ITmfCheckpoint.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/checkpoint/TmfCheckpoint.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/checkpoint/TmfCheckpointIndexer.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/ITmfLocation.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/TmfLocation.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/TmfLongLocation.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/TmfTimestampLocation.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomTxtTrace.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomTxtTraceContext.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomXmlTrace.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomXmlTraceContext.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/rawviewer/TmfRawEventViewer.java

index 9f49f3b68d082e6dcceb86ad58588cad311beea1..431930c33ddd8cf632d796a6c843fcfc4cb5a531 100644 (file)
@@ -31,10 +31,10 @@ import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 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.TmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
 
 /**
  * GDB Tracepoint extension of TmfTrace. This class implements the necessary
index 7723e75a802de6f1aa44ea67af1640cc6d337820..56ea7f2826800829105648b81a81f235e07627aa 100644 (file)
@@ -30,6 +30,8 @@ import org.junit.runners.Suite;
     org.eclipse.linuxtools.tmf.core.tests.statesystem.AllTests.class,
     org.eclipse.linuxtools.tmf.core.tests.statistics.AllTests.class,
     org.eclipse.linuxtools.tmf.core.tests.trace.AllTests.class,
+    org.eclipse.linuxtools.tmf.core.tests.trace.indexer.checkpoint.AllTests.class,
+    org.eclipse.linuxtools.tmf.core.tests.trace.location.AllTests.class,
     org.eclipse.linuxtools.tmf.core.tests.uml2sd.AllTests.class,
     org.eclipse.linuxtools.tmf.core.tests.util.AllTests.class
 })
index 52eb7f0000a5e9a59ccec890ecbf164741e5b4d5..8317efe92b8faba2a047a98ab772692c06cfdacd 100644 (file)
@@ -22,17 +22,10 @@ import org.junit.runners.Suite;
  */
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
-    TmfCheckpointIndexTest.class,
-    TmfCheckpointIndexTest2.class,
-    TmfCheckpointTest.class,
     TmfContextTest.class,
-    TmfExperimentCheckpointIndexTest.class,
     TmfExperimentTest.class,
-    TmfLocationTest.class,
     TmfMultiTraceExperimentTest.class,
     TmfTraceManagerTest.class,
     TmfTraceTest.class
 })
-public class AllTests {
-
-}
\ No newline at end of file
+public class AllTests {}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java
deleted file mode 100644 (file)
index c727241..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-/*******************************************************************************
- * 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *   Francois Chouinard - Adapted for TMF Trace Model 1.0
- *   Alexandre Montplaisir - Port to JUnit4
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.trace;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
-import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfEmptyTraceStub;
-import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test suite for the TmfCheckpointIndexTest class.
- */
-@SuppressWarnings("javadoc")
-public class TmfCheckpointIndexTest {
-
-    // ------------------------------------------------------------------------
-    // Variables
-    // ------------------------------------------------------------------------
-
-    private static final String    DIRECTORY   = "testfiles";
-    private static final String    TEST_STREAM = "A-Test-10K";
-    private static final int       BLOCK_SIZE  = 100;
-    private static final int       NB_EVENTS   = 10000;
-    private static TestTrace       fTrace      = null;
-    private static EmptyTestTrace  fEmptyTrace = null;
-
-    // ------------------------------------------------------------------------
-    // Housekeeping
-    // ------------------------------------------------------------------------
-
-    @Before
-    public void setUp() {
-        setupTrace(DIRECTORY + File.separator + TEST_STREAM);
-    }
-
-    @After
-    public void tearDown() {
-        fTrace.dispose();
-        fTrace = null;
-        fEmptyTrace.dispose();
-        fEmptyTrace = null;
-    }
-
-    // ------------------------------------------------------------------------
-    // Helper classes
-    // ------------------------------------------------------------------------
-
-    private static class TestIndexer extends TmfCheckpointIndexer {
-        @SuppressWarnings({ })
-        public TestIndexer(TestTrace testTrace) {
-            super(testTrace, BLOCK_SIZE);
-        }
-        @SuppressWarnings({ })
-        public TestIndexer(EmptyTestTrace testTrace) {
-            super(testTrace, BLOCK_SIZE);
-        }
-        public List<ITmfCheckpoint> getCheckpoints() {
-            return getTraceIndex();
-        }
-    }
-
-    private class TestTrace extends TmfTraceStub {
-        public TestTrace(String path, int blockSize) throws TmfTraceException {
-            super(path, blockSize);
-            setIndexer(new TestIndexer(this));
-        }
-        @Override
-        public TestIndexer getIndexer() {
-            return (TestIndexer) super.getIndexer();
-        }
-    }
-
-    private class EmptyTestTrace extends TmfEmptyTraceStub {
-        public EmptyTestTrace() {
-            super();
-            setIndexer(new TestIndexer(this));
-        }
-        @Override
-        public TestIndexer getIndexer() {
-            return (TestIndexer) super.getIndexer();
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // Helper functions
-    // ------------------------------------------------------------------------
-
-    private synchronized void setupTrace(final String path) {
-        if (fTrace == null) {
-            try {
-                final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
-                final File test = new File(FileLocator.toFileURL(location).toURI());
-                fTrace = new TestTrace(test.toURI().getPath(), BLOCK_SIZE);
-                fTrace.indexTrace(true);
-            } catch (final TmfTraceException e) {
-                e.printStackTrace();
-            } catch (final URISyntaxException e) {
-                e.printStackTrace();
-            } catch (final IOException e) {
-                e.printStackTrace();
-            }
-        }
-
-        if (fEmptyTrace == null) {
-            fEmptyTrace = new EmptyTestTrace();
-            fEmptyTrace.indexTrace(true);
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // Verify checkpoints
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testTmfTraceIndexing() {
-        assertEquals("getCacheSize",   BLOCK_SIZE, fTrace.getCacheSize());
-        assertEquals("getTraceSize",   NB_EVENTS,  fTrace.getNbEvents());
-        assertEquals("getRange-start", 1,          fTrace.getTimeRange().getStartTime().getValue());
-        assertEquals("getRange-end",   NB_EVENTS,  fTrace.getTimeRange().getEndTime().getValue());
-        assertEquals("getStartTime",   1,          fTrace.getStartTime().getValue());
-        assertEquals("getEndTime",     NB_EVENTS,  fTrace.getEndTime().getValue());
-
-        List<ITmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
-        int pageSize = fTrace.getCacheSize();
-        assertTrue("Checkpoints exist",  checkpoints != null);
-        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
-
-        // Validate that each checkpoint points to the right event
-        for (int i = 0; i < checkpoints.size(); i++) {
-            ITmfCheckpoint checkpoint = checkpoints.get(i);
-            TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
-            ITmfEvent event = fTrace.parseEvent(context);
-            assertTrue(context.getRank() == i * pageSize);
-            assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
-        }
-    }
-
-    @Test
-    public void testEmptyTmfTraceIndexing() {
-        assertEquals("getCacheSize",   ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, fEmptyTrace.getCacheSize());
-        assertEquals("getTraceSize",   0,  fEmptyTrace.getNbEvents());
-        assertEquals("getRange-start", TmfTimestamp.BIG_BANG, fEmptyTrace.getTimeRange().getStartTime());
-        assertEquals("getRange-end",   TmfTimestamp.BIG_BANG, fEmptyTrace.getTimeRange().getEndTime());
-        assertEquals("getStartTime",   TmfTimestamp.BIG_BANG, fEmptyTrace.getStartTime());
-        assertEquals("getEndTime",     TmfTimestamp.BIG_BANG, fEmptyTrace.getEndTime());
-
-        List<ITmfCheckpoint> checkpoints = fEmptyTrace.getIndexer().getCheckpoints();
-        int pageSize = fEmptyTrace.getCacheSize();
-        assertTrue("Checkpoints exist",  checkpoints != null);
-        assertEquals("Checkpoints size", 0, checkpoints.size());
-
-        // Validate that each checkpoint points to the right event
-        for (int i = 0; i < checkpoints.size(); i++) {
-            ITmfCheckpoint checkpoint = checkpoints.get(i);
-            TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
-            ITmfEvent event = fEmptyTrace.parseEvent(context);
-            assertTrue(context.getRank() == i * pageSize);
-            assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
-        }
-    }
-
-}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest2.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest2.java
deleted file mode 100644 (file)
index fd150ca..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Bernd Hufmann - Initial API and implementation
- *   Alexandre Montplaisir - Port to JUnit4
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.trace;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
-import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfEmptyTraceStub;
-import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test suite for the TmfCheckpointIndexer class (events with same
- * timestamp around checkpoint).
- */
-@SuppressWarnings("javadoc")
-public class TmfCheckpointIndexTest2 {
-
-    // ------------------------------------------------------------------------
-    // Variables
-    // ------------------------------------------------------------------------
-
-    private static final String    DIRECTORY   = "testfiles";
-    // Trace has 3 events at t=101 at rank 99, 100, 101
-    // Trace has events with same timestamp (ts=102) for ranks 102..702 -> 2 checkpoints with same timestamp are created
-    private static final String    TEST_STREAM = "A-Test-10K-2";
-    private static final int       BLOCK_SIZE  = 100;
-    private static final int       NB_EVENTS   = 702;
-    private static TestTrace       fTrace      = null;
-    private static EmptyTestTrace  fEmptyTrace = null;
-
-    // ------------------------------------------------------------------------
-    // Housekeeping
-    // ------------------------------------------------------------------------
-
-    @Before
-    public void setUp() {
-        setupTrace(DIRECTORY + File.separator + TEST_STREAM);
-    }
-
-    @After
-    public void tearDown() {
-        fTrace.dispose();
-        fTrace = null;
-        fEmptyTrace.dispose();
-        fEmptyTrace = null;
-    }
-
-    // ------------------------------------------------------------------------
-    // Helper classes
-    // ------------------------------------------------------------------------
-
-    private static class TestIndexer extends TmfCheckpointIndexer {
-        @SuppressWarnings({ })
-        public TestIndexer(TestTrace testTrace) {
-            super(testTrace, BLOCK_SIZE);
-        }
-        @SuppressWarnings({ })
-        public TestIndexer(EmptyTestTrace testTrace) {
-            super(testTrace, BLOCK_SIZE);
-        }
-        public List<ITmfCheckpoint> getCheckpoints() {
-            return getTraceIndex();
-        }
-    }
-
-    private class TestTrace extends TmfTraceStub {
-        public TestTrace(String path, int blockSize) throws TmfTraceException {
-            super(path, blockSize);
-            setIndexer(new TestIndexer(this));
-        }
-        @Override
-        public TestIndexer getIndexer() {
-            return (TestIndexer) super.getIndexer();
-        }
-    }
-
-    private class EmptyTestTrace extends TmfEmptyTraceStub {
-        public EmptyTestTrace() {
-            super();
-            setIndexer(new TestIndexer(this));
-        }
-        @Override
-        public TestIndexer getIndexer() {
-            return (TestIndexer) super.getIndexer();
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // Helper functions
-    // ------------------------------------------------------------------------
-
-    private synchronized void setupTrace(final String path) {
-        if (fTrace == null) {
-            try {
-                final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
-                final File test = new File(FileLocator.toFileURL(location).toURI());
-                fTrace = new TestTrace(test.toURI().getPath(), BLOCK_SIZE);
-                fTrace.indexTrace(true);
-            } catch (final TmfTraceException e) {
-                e.printStackTrace();
-            } catch (final URISyntaxException e) {
-                e.printStackTrace();
-            } catch (final IOException e) {
-                e.printStackTrace();
-            }
-        }
-
-        if (fEmptyTrace == null) {
-            fEmptyTrace = new EmptyTestTrace();
-            fEmptyTrace.indexTrace(true);
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // Verify checkpoints
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testTmfTraceMultiTimestamps() {
-        assertEquals("getCacheSize",   BLOCK_SIZE, fTrace.getCacheSize());
-        assertEquals("getTraceSize",   NB_EVENTS,  fTrace.getNbEvents());
-        assertEquals("getRange-start", 1,          fTrace.getTimeRange().getStartTime().getValue());
-        assertEquals("getRange-end",   102,        fTrace.getTimeRange().getEndTime().getValue());
-        assertEquals("getStartTime",   1,          fTrace.getStartTime().getValue());
-        assertEquals("getEndTime",     102,        fTrace.getEndTime().getValue());
-
-        List<ITmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
-        assertTrue("Checkpoints exist",  checkpoints != null);
-        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE + 1, checkpoints.size());
-
-        // Trace has 3 events with same timestamp (ts=101) at rank 99, 100, 101
-
-        // Verify that the event at rank=99 is returned when seeking to ts=101 (first event with this timestamp)
-        // and not the event at checkpoint boundary
-        TmfTimestamp seekTs = new TmfTimestamp(101, -3, 0);
-        ITmfContext ctx = fTrace.seekEvent(seekTs);
-        ITmfEvent event = fTrace.getNext(ctx);
-
-        assertEquals(99, ctx.getRank());
-        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
-
-        event = fTrace.getNext(ctx);
-
-        assertEquals(100, ctx.getRank());
-        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
-
-        event = fTrace.getNext(ctx);
-
-        assertEquals(101, ctx.getRank());
-        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
-
-        // Trace has events with same timestamp (ts=102) for ranks 102..702 -> 2 checkpoints with same timestamp are created
-        // Verify that the event at rank=102 is returned when seeking to ts=102 (first event with this timestamp)
-        // and not the event at checkpoint boundary
-        seekTs = new TmfTimestamp(102, -3, 0);
-        ctx = fTrace.seekEvent(seekTs);
-        event = fTrace.getNext(ctx);
-
-        assertEquals(102, ctx.getRank());
-        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
-
-        // Verify seek to first checkpoint
-        seekTs = new TmfTimestamp(1, -3, 0);
-        ctx = fTrace.seekEvent(seekTs);
-        event = fTrace.getNext(ctx);
-
-        assertEquals(1, ctx.getRank());
-        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
-
-        // Verify seek to timestamp before first event
-        seekTs = new TmfTimestamp(0, -3, 0);
-        ctx = fTrace.seekEvent(seekTs);
-        event = fTrace.getNext(ctx);
-
-        assertEquals(1, ctx.getRank());
-        assertEquals(0, new TmfTimestamp(1, -3, 0).compareTo(event.getTimestamp(), false));
-
-        // Verify seek to timestamp between first and second checkpoint
-        seekTs = new TmfTimestamp(50, -3, 0);
-        ctx = fTrace.seekEvent(seekTs);
-        event = fTrace.getNext(ctx);
-
-        assertEquals(50, ctx.getRank());
-        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
-
-        // Verify seek to timestamp after last event in trace
-        seekTs = new TmfTimestamp(103, -3, 0);
-        ctx = fTrace.seekEvent(seekTs);
-        event = fTrace.getNext(ctx);
-
-        assertEquals(-1, ctx.getRank());
-        assertNull(event);
-    }
-}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java
deleted file mode 100644 (file)
index ce86292..0000000
+++ /dev/null
@@ -1,239 +0,0 @@
-/*******************************************************************************
- * 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *   Francois Chouinard - Adapted for TMF Trace Model 1.0
- *   Alexandre Montplaisir - Port to JUnit4
- *   Patrick Tasse - Updated for location in checkpoint
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.trace;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
-import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
-import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
-import org.junit.Test;
-
-/**
- * Test suite for the TmfCheckpoint class.
- */
-@SuppressWarnings("javadoc")
-public class TmfCheckpointTest {
-
-    // ------------------------------------------------------------------------
-    // Variables
-    // ------------------------------------------------------------------------
-
-    private ITmfTimestamp fTimestamp1 = new TmfTimestamp();
-    private ITmfTimestamp fTimestamp2 = TmfTimestamp.BIG_BANG;
-    private ITmfTimestamp fTimestamp3 = TmfTimestamp.BIG_CRUNCH;
-
-    private Long aLong1 = 12345L;
-    private Long aLong2 = 23456L;
-    private Long aLong3 = 34567L;
-    private ITmfLocation fLocation1 = new TmfLongLocation(aLong1);
-    private ITmfLocation fLocation2 = new TmfLongLocation(aLong2);
-    private ITmfLocation fLocation3 = new TmfLongLocation(aLong3);
-
-    private TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1);
-    private TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, fLocation2);
-    private TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, fLocation3);
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testTmfCheckpoint() {
-        assertEquals("TmfCheckpoint", fTimestamp1, fCheckpoint1.getTimestamp());
-        assertEquals("TmfCheckpoint", fLocation1,  fCheckpoint1.getLocation());
-    }
-
-    public void testTmfLocationCopy() {
-        final TmfCheckpoint checkpoint = new TmfCheckpoint(fCheckpoint1);
-
-        assertEquals("TmfCheckpoint", fTimestamp1, checkpoint.getTimestamp());
-        assertEquals("TmfCheckpoint", fLocation1,  checkpoint.getLocation());
-    }
-
-    @Test
-    public void testTmfLocationCopy2() {
-        try {
-            new TmfCheckpoint(null);
-            fail("null copy");
-        }
-        catch (final IllegalArgumentException e) {
-            // Success
-        }
-        catch (final Exception e) {
-            fail("wrong exception");
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // compareTo
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testCompareTo() {
-        assertEquals("compareTo",  0, fCheckpoint1.compareTo(fCheckpoint1));
-        assertEquals("compareTo",  1, fCheckpoint1.compareTo(fCheckpoint2));
-        assertEquals("compareTo", -1, fCheckpoint1.compareTo(fCheckpoint3));
-
-        assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint1));
-        assertEquals("compareTo",  0, fCheckpoint2.compareTo(fCheckpoint2));
-        assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint3));
-
-        assertEquals("compareTo",  1, fCheckpoint3.compareTo(fCheckpoint1));
-        assertEquals("compareTo",  1, fCheckpoint3.compareTo(fCheckpoint2));
-        assertEquals("compareTo",  0, fCheckpoint3.compareTo(fCheckpoint3));
-    }
-
-    @Test
-    public void testCompareToNull() {
-        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, fLocation1);
-        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(null, fLocation2);
-        final TmfCheckpoint checkpoint3 = new TmfCheckpoint(null, fLocation3);
-        final TmfCheckpoint checkpoint4 = new TmfCheckpoint(null, fLocation1);
-
-        // Test the various 'null' vs. '!null' combinations
-        assertEquals("compareTo",  0, checkpoint1.compareTo(fCheckpoint1));
-        assertEquals("compareTo",  0, fCheckpoint1.compareTo(checkpoint1));
-        assertEquals("compareTo", -1, checkpoint1.compareTo(fCheckpoint2));
-        assertEquals("compareTo",  1, fCheckpoint2.compareTo(checkpoint1));
-        assertEquals("compareTo", -1, checkpoint1.compareTo(fCheckpoint3));
-        assertEquals("compareTo",  1, fCheckpoint3.compareTo(checkpoint1));
-
-        // Test the 'null' vs. 'null' combinations
-        assertEquals("compareTo",  0, checkpoint1.compareTo(checkpoint4));
-        assertEquals("compareTo",  0, checkpoint4.compareTo(checkpoint1));
-        assertEquals("compareTo", -1, checkpoint1.compareTo(checkpoint2));
-        assertEquals("compareTo",  1, checkpoint2.compareTo(checkpoint1));
-        assertEquals("compareTo", -1, checkpoint1.compareTo(checkpoint3));
-        assertEquals("compareTo",  1, checkpoint3.compareTo(checkpoint1));
-    }
-
-    // ------------------------------------------------------------------------
-    // hashCode
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testHashCode() {
-        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1);
-        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2);
-
-        assertTrue("hashCode", fCheckpoint1.hashCode() == checkpoint1.hashCode());
-        assertTrue("hashCode", fCheckpoint2.hashCode() == checkpoint2.hashCode());
-
-        assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint2.hashCode());
-        assertTrue("hashCode", fCheckpoint2.hashCode() != checkpoint1.hashCode());
-    }
-
-    @Test
-    public void testHashCodeNull() {
-        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, fLocation1);
-        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp1, null);
-        final TmfCheckpoint checkpoint3 = new TmfCheckpoint(checkpoint1);
-        final TmfCheckpoint checkpoint4 = new TmfCheckpoint(checkpoint2);
-
-        assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint1.hashCode());
-        assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint2.hashCode());
-
-        assertTrue("hashCode", checkpoint1.hashCode() == checkpoint3.hashCode());
-        assertTrue("hashCode", checkpoint2.hashCode() == checkpoint4.hashCode());
-    }
-
-    // ------------------------------------------------------------------------
-    // equals
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testEqualsReflexivity() {
-        assertTrue("equals", fCheckpoint1.equals(fCheckpoint1));
-        assertTrue("equals", fCheckpoint2.equals(fCheckpoint2));
-
-        assertTrue("equals", !fCheckpoint1.equals(fCheckpoint2));
-        assertTrue("equals", !fCheckpoint2.equals(fCheckpoint1));
-    }
-
-    @Test
-    public void testEqualsSymmetry() {
-        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1);
-        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2);
-
-        assertTrue("equals", checkpoint1.equals(fCheckpoint1));
-        assertTrue("equals", fCheckpoint1.equals(checkpoint1));
-
-        assertTrue("equals", checkpoint2.equals(fCheckpoint2));
-        assertTrue("equals", fCheckpoint2.equals(checkpoint2));
-    }
-
-    @Test
-    public void testEqualsTransivity() {
-        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1);
-        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(checkpoint1);
-        final TmfCheckpoint checkpoint3 = new TmfCheckpoint(checkpoint2);
-
-        assertTrue("equals", checkpoint1.equals(checkpoint2));
-        assertTrue("equals", checkpoint2.equals(checkpoint3));
-        assertTrue("equals", checkpoint1.equals(checkpoint3));
-    }
-
-    @Test
-    public void testNotEqual() {
-        // Various checkpoints
-        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1);
-        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp2, fLocation1);
-        final TmfCheckpoint checkpoint3 = new TmfCheckpoint(fTimestamp1, fLocation2);
-        final TmfCheckpoint checkpoint4 = new TmfCheckpoint(fTimestamp1, null);
-        final TmfCheckpoint checkpoint5 = new TmfCheckpoint(null, fLocation1);
-
-        // Null check
-        assertFalse("equals", checkpoint1.equals(null));
-
-        // Different types
-        assertFalse("equals", checkpoint1.equals(new TmfTimestamp()));
-
-        // Null locations/location
-        assertFalse("equals", checkpoint1.equals(checkpoint4));
-        assertFalse("equals", checkpoint1.equals(checkpoint5));
-        assertFalse("equals", checkpoint4.equals(checkpoint1));
-        assertFalse("equals", checkpoint5.equals(checkpoint1));
-
-        // Different locations/location
-        assertFalse("equals", checkpoint1.equals(checkpoint2));
-        assertFalse("equals", checkpoint1.equals(checkpoint3));
-    }
-
-    // ------------------------------------------------------------------------
-    // toString
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testToString() {
-        final String expected1 = "TmfCheckpoint [fLocation=" + fCheckpoint1.getLocation() +
-                ", fTimestamp=" + fCheckpoint1.getTimestamp() + "]";
-        final String expected2 = "TmfCheckpoint [fLocation=" + fCheckpoint2.getLocation() +
-                ", fTimestamp=" + fCheckpoint2.getTimestamp() + "]";
-        final String expected3 = "TmfCheckpoint [fLocation=" + fCheckpoint3.getLocation() +
-                ", fTimestamp=" + fCheckpoint3.getTimestamp() + "]";
-
-        assertEquals("toString", expected1, fCheckpoint1.toString());
-        assertEquals("toString", expected2, fCheckpoint2.toString());
-        assertEquals("toString", expected3, fCheckpoint3.toString());
-    }
-
-}
index 17be19fe846f3372a2e14f27a5959fe71ab59f70..27038945252745d11ee7c13d009fd2d014b1d025 100644 (file)
@@ -20,11 +20,12 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import org.eclipse.linuxtools.tmf.core.tests.trace.location.TmfStringLocation;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
-import org.eclipse.linuxtools.tmf.core.trace.TmfTimestampLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfTimestampLocation;
 import org.junit.Test;
 
 /**
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentCheckpointIndexTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentCheckpointIndexTest.java
deleted file mode 100644 (file)
index 1ca14b0..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *   Alexandre Montplaisir - Port to JUnit4
- *   Patrick Tasse - Updated for ranks in experiment location
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.trace;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub;
-import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test suite for the TmfCheckpointIndexTest class.
- */
-@SuppressWarnings("javadoc")
-public class TmfExperimentCheckpointIndexTest {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    private static final String DIRECTORY    = "testfiles";
-    private static final String TEST_STREAM1 = "O-Test-10K";
-    private static final String TEST_STREAM2 = "E-Test-10K";
-    private static final String EXPERIMENT   = "MyExperiment";
-    private static int          NB_EVENTS    = 20000;
-    private static int          BLOCK_SIZE   = 1000;
-
-    private static ITmfTrace[] fTestTraces;
-    private static TmfExperimentStub fExperiment;
-
-    // ------------------------------------------------------------------------
-    // Housekeeping
-    // ------------------------------------------------------------------------
-
-    @Before
-    public void setUp() {
-        setupTraces();
-        fExperiment = new TmfExperimentStub(EXPERIMENT, fTestTraces, BLOCK_SIZE);
-        fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
-    }
-
-    @After
-    public void tearDown() {
-        fExperiment.dispose();
-        fExperiment = null;
-        for (ITmfTrace trace : fTestTraces) {
-            trace.dispose();
-        }
-        fTestTraces = null;
-    }
-
-    private static void setupTraces() {
-        final String path1 = DIRECTORY + File.separator + TEST_STREAM1;
-        final String path2 = DIRECTORY + File.separator + TEST_STREAM2;
-
-        fTestTraces = new ITmfTrace[2];
-        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);
-            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);
-            fTestTraces[1] = trace2;
-        } catch (final TmfTraceException e) {
-            e.printStackTrace();
-        } catch (final URISyntaxException e) {
-            e.printStackTrace();
-        } catch (final IOException e) {
-            e.printStackTrace();
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // Verify checkpoints
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testTmfTraceIndexing() {
-        assertEquals("getCacheSize",   BLOCK_SIZE, fExperiment.getCacheSize());
-        assertEquals("getTraceSize",   NB_EVENTS,  fExperiment.getNbEvents());
-        assertEquals("getRange-start", 1,          fExperiment.getTimeRange().getStartTime().getValue());
-        assertEquals("getRange-end",   NB_EVENTS,  fExperiment.getTimeRange().getEndTime().getValue());
-        assertEquals("getStartTime",   1,          fExperiment.getStartTime().getValue());
-        assertEquals("getEndTime",     NB_EVENTS,  fExperiment.getEndTime().getValue());
-
-        List<ITmfCheckpoint> checkpoints = fExperiment.getIndexer().getCheckpoints();
-        int pageSize = fExperiment.getCacheSize();
-        assertTrue("Checkpoints exist",  checkpoints != null);
-        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
-
-        // Validate that each checkpoint points to the right event
-        for (int i = 0; i < checkpoints.size(); i++) {
-            ITmfCheckpoint checkpoint = checkpoints.get(i);
-            ITmfLocation location = checkpoint.getLocation();
-            ITmfContext context = fExperiment.seekEvent(location);
-            ITmfEvent event = fExperiment.parseEvent(context);
-            assertTrue(context.getRank() == i * pageSize);
-            assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // Streaming
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testGrowingIndex() {
-        ITmfTrace[] testTraces = new TmfTraceStub[2];
-        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);
-            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);
-            testTraces[1] = trace2;
-        } catch (final TmfTraceException e) {
-            e.printStackTrace();
-        } catch (final URISyntaxException e) {
-            e.printStackTrace();
-        } catch (final IOException e) {
-            e.printStackTrace();
-        }
-
-        TmfExperimentStub experiment = new TmfExperimentStub(EXPERIMENT, testTraces, BLOCK_SIZE);
-        int pageSize = experiment.getCacheSize();
-
-        // Build the first half of the index
-        TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(1, -3), new TmfTimestamp(NB_EVENTS / 2 - 1, -3));
-        experiment.getIndexer().buildIndex(0, range, true);
-
-        // Validate that each checkpoint points to the right event
-        List<ITmfCheckpoint> checkpoints = experiment.getIndexer().getCheckpoints();
-        assertTrue("Checkpoints exist",  checkpoints != null);
-        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE / 2, checkpoints.size());
-
-        // Build the second half of the index
-        experiment.getIndexer().buildIndex(NB_EVENTS / 2, TmfTimeRange.ETERNITY, true);
-
-        // Validate that each checkpoint points to the right event
-        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
-        for (int i = 0; i < checkpoints.size(); i++) {
-            ITmfCheckpoint checkpoint = checkpoints.get(i);
-            ITmfLocation location = checkpoint.getLocation();
-            ITmfContext context = experiment.seekEvent(location);
-            ITmfEvent event = experiment.parseEvent(context);
-            assertTrue(context.getRank() == i * pageSize);
-            assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
-            assertEquals("Checkpoint value", i * pageSize + 1, checkpoint.getTimestamp().getValue());
-        }
-
-        /* Clean up (since we didn't use the class-specific fixtures) */
-        experiment.dispose();
-        for (ITmfTrace trace : testTraces) {
-            trace.dispose();
-        }
-    }
-
-}
\ No newline at end of file
index 3792321f595f011836feb8d45e9a62d2d3f92f9a..23e7327c8b55037851b6decc259ae16c08a7ab89 100644 (file)
@@ -42,10 +42,10 @@ import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
-import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub;
 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
 import org.junit.Before;
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java
deleted file mode 100644 (file)
index 82ff267..0000000
+++ /dev/null
@@ -1,248 +0,0 @@
-/*******************************************************************************
- * 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *   Alexandre Montplaisir - Port to JUnit4
- *   Patrick Tasse - Add tests for TmfExperimentLocation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.trace;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation;
-import org.eclipse.linuxtools.internal.tmf.core.trace.TmfLocationArray;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
-import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
-import org.eclipse.linuxtools.tmf.core.trace.TmfTimestampLocation;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test suite for the TmfLocation class.
- */
-@SuppressWarnings("javadoc")
-public class TmfLocationTest {
-
-    // ------------------------------------------------------------------------
-    // Variables
-    // ------------------------------------------------------------------------
-
-    private String aString = "some location";
-    private Long aLong = 12345L;
-    private TmfTimestamp aTimestamp = new TmfTimestamp();
-    private TmfLocationArray aLocationArray;
-
-    private TmfStringLocation fLocation1;
-    private TmfStringLocation fLocation2;
-    private TmfLongLocation fLocation3;
-    private TmfTimestampLocation fLocation4;
-    private TmfExperimentLocation fExpLocation;
-
-    // ------------------------------------------------------------------------
-    // Housekeeping
-    // ------------------------------------------------------------------------
-
-    @Before
-    public void setUp() {
-        fLocation1 = new TmfStringLocation((String) null);
-        fLocation2 = new TmfStringLocation(aString);
-        fLocation3 = new TmfLongLocation(aLong);
-        fLocation4 = new TmfTimestampLocation(aTimestamp);
-        aLocationArray = new TmfLocationArray(
-                new ITmfLocation[] { fLocation1, fLocation2, fLocation3, fLocation4 },
-                new long[] { 1, 2, 3, 4 }
-                );
-        fExpLocation = new TmfExperimentLocation(aLocationArray);
-    }
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testTmfLocation() {
-        assertNull("TmfLocation", fLocation1.getLocationInfo());
-        assertEquals("TmfLocation", aString, fLocation2.getLocationInfo());
-        assertEquals("TmfLocation", aLong, fLocation3.getLocationInfo());
-        assertEquals("TmfLocation", aTimestamp, fLocation4.getLocationInfo());
-        assertEquals("TmfLocation", aLocationArray, fExpLocation.getLocationInfo());
-    }
-
-    @Test
-    public void testTmfLocationCopy() {
-        TmfStringLocation location1 = new TmfStringLocation(fLocation1);
-        TmfStringLocation location2 = new TmfStringLocation(fLocation2);
-        TmfLongLocation location3 = new TmfLongLocation(fLocation3);
-        TmfTimestampLocation location4 = new TmfTimestampLocation(fLocation4);
-        TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation);
-
-        assertNull("TmfLocation", location1.getLocationInfo());
-        assertEquals("TmfLocation", aString, location2.getLocationInfo());
-        assertEquals("TmfLocation", aLong, location3.getLocationInfo());
-        assertEquals("TmfLocation", aTimestamp, location4.getLocationInfo());
-        assertEquals("TmfLocation", aLocationArray, expLocation.getLocationInfo());
-    }
-
-    // ------------------------------------------------------------------------
-    // hashCode
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testHashCode() {
-        TmfStringLocation location1 = new TmfStringLocation((String) null);
-        TmfStringLocation location2 = new TmfStringLocation(aString);
-        TmfLongLocation location3 = new TmfLongLocation(aLong);
-        TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation);
-        TmfLocationArray locationArray1 = new TmfLocationArray(aLocationArray, 3, fLocation4, 5);
-        TmfExperimentLocation expLocation1 = new TmfExperimentLocation(locationArray1);
-        TmfLocationArray locationArray2 = new TmfLocationArray(aLocationArray, 3, fLocation3, 4);
-        TmfExperimentLocation expLocation2 = new TmfExperimentLocation(locationArray2);
-        TmfLocationArray locationArray3 = new TmfLocationArray(
-                new ITmfLocation[] { fLocation1, fLocation2, fLocation3 },
-                new long[] { 1, 2, 3 }
-                );
-        TmfExperimentLocation expLocation3 = new TmfExperimentLocation(locationArray3);
-
-        assertTrue("hashCode", fLocation1.hashCode() == location1.hashCode());
-        assertTrue("hashCode", fLocation2.hashCode() == location2.hashCode());
-        assertTrue("hashCode", fLocation3.hashCode() == location3.hashCode());
-        assertTrue("hashCode", fExpLocation.hashCode() == expLocation.hashCode());
-
-        assertTrue("hashCode", fLocation2.hashCode() != location3.hashCode());
-        assertTrue("hashCode", fLocation3.hashCode() != location2.hashCode());
-        assertTrue("hashCode", fExpLocation.hashCode() != expLocation1.hashCode());
-        assertTrue("hashCode", fExpLocation.hashCode() != expLocation2.hashCode());
-        assertTrue("hashCode", fExpLocation.hashCode() != expLocation3.hashCode());
-    }
-
-    // ------------------------------------------------------------------------
-    // toEquals
-    // ------------------------------------------------------------------------
-
-    private static class TmfLocation2 extends TmfStringLocation {
-        public TmfLocation2(String location) {
-            super(location);
-        }
-    }
-
-    @Test
-    public void testEqualsWrongTypes() {
-        ITmfLocation location1 = new TmfStringLocation(aString);
-        TmfLocation2 location2 = new TmfLocation2(aString);
-
-        assertFalse("equals", location1.equals(location2));
-        assertFalse("equals", location2.equals(location1));
-    }
-
-    @Test
-    public void testEqualsWithNulls() {
-        TmfStringLocation location1 = new TmfStringLocation(aString);
-        TmfStringLocation location2 = new TmfStringLocation((String) null);
-
-        assertFalse("equals", location1.equals(location2));
-        assertFalse("equals", location2.equals(location1));
-    }
-
-    @Test
-    public void testEqualsReflexivity() {
-        assertTrue("equals", fLocation2.equals(fLocation2));
-        assertTrue("equals", fLocation3.equals(fLocation3));
-        assertTrue("equals", fExpLocation.equals(fExpLocation));
-
-        assertTrue("equals", !fLocation2.equals(fLocation3));
-        assertTrue("equals", !fLocation3.equals(fLocation2));
-        TmfLocationArray locationArray1 = new TmfLocationArray(aLocationArray, 3, fLocation4, 5);
-        TmfExperimentLocation expLocation1 = new TmfExperimentLocation(locationArray1);
-        TmfLocationArray locationArray2 = new TmfLocationArray(aLocationArray, 3, fLocation3, 4);
-        TmfExperimentLocation expLocation2 = new TmfExperimentLocation(locationArray2);
-        TmfLocationArray locationArray3 = new TmfLocationArray(
-                new ITmfLocation[] { fLocation1, fLocation2, fLocation3 },
-                new long[] { 1, 2, 3 }
-                );
-        TmfExperimentLocation expLocation3 = new TmfExperimentLocation(locationArray3);
-        assertTrue("equals", !fExpLocation.equals(expLocation1));
-        assertTrue("equals", !expLocation1.equals(fExpLocation));
-        assertTrue("equals", !fExpLocation.equals(expLocation2));
-        assertTrue("equals", !expLocation2.equals(fExpLocation));
-        assertTrue("equals", !fExpLocation.equals(expLocation3));
-        assertTrue("equals", !expLocation3.equals(fExpLocation));
-    }
-
-    @Test
-    public void testEqualsSymmetry() {
-        TmfStringLocation location2 = new TmfStringLocation(aString);
-        TmfLongLocation location3 = new TmfLongLocation(aLong);
-        TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation);
-
-        assertTrue("equals", location2.equals(fLocation2));
-        assertTrue("equals", fLocation2.equals(location2));
-
-        assertTrue("equals", location3.equals(fLocation3));
-        assertTrue("equals", fLocation3.equals(location3));
-
-        assertTrue("equals", expLocation.equals(fExpLocation));
-        assertTrue("equals", fExpLocation.equals(expLocation));
-    }
-
-    @Test
-    public void testEqualsTransivity() {
-        TmfStringLocation location1 = new TmfStringLocation(aString);
-        TmfStringLocation location2 = new TmfStringLocation(aString);
-        TmfStringLocation location3 = new TmfStringLocation(aString);
-        TmfExperimentLocation expLocation1 = new TmfExperimentLocation(aLocationArray);
-        TmfExperimentLocation expLocation2 = new TmfExperimentLocation(aLocationArray);
-        TmfExperimentLocation expLocation3 = new TmfExperimentLocation(aLocationArray);
-
-        assertTrue("equals", location1.equals(location2));
-        assertTrue("equals", location2.equals(location3));
-        assertTrue("equals", location3.equals(location1));
-        assertTrue("equals", expLocation1.equals(expLocation2));
-        assertTrue("equals", expLocation2.equals(expLocation3));
-        assertTrue("equals", expLocation3.equals(expLocation1));
-    }
-
-    @Test
-    public void testEqualsNull() {
-        assertTrue("equals", !fLocation2.equals(null));
-        assertTrue("equals", !fLocation2.equals(null));
-        assertTrue("equals", !fExpLocation.equals(null));
-    }
-
-    // ------------------------------------------------------------------------
-    // toString
-    // ------------------------------------------------------------------------
-
-    @Test
-    public void testToString() {
-        String str = "some location";
-        Long lng = 12345L;
-        TmfTimestamp ts = new TmfTimestamp();
-
-        TmfStringLocation location1 = new TmfStringLocation(str);
-        TmfLongLocation location2 = new TmfLongLocation(lng);
-        TmfTimestampLocation location3 = new TmfTimestampLocation(ts);
-        TmfExperimentLocation expLocation = new TmfExperimentLocation(aLocationArray);
-
-        String expected1 = "TmfStringLocation [fLocationInfo=" + str + "]";
-        String expected2 = "TmfLongLocation [fLocationInfo=" + lng + "]";
-        String expected3 = "TmfTimestampLocation [fLocationInfo=" + ts + "]";
-        String expected4 = "TmfExperimentLocation [" + aLocationArray + "]";
-
-        assertEquals("toString", expected1, location1.toString());
-        assertEquals("toString", expected2, location2.toString());
-        assertEquals("toString", expected3, location3.toString());
-        assertEquals("toString", expected4, expLocation.toString());
-    }
-
-}
index e04ff345d6cc8e019042bfe6f5b6f43b1bdeff79..e497747249a178a8e4c47481d913156f734c9ea7 100644 (file)
@@ -39,8 +39,8 @@ import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub;
 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
 import org.junit.AfterClass;
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfStringLocation.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfStringLocation.java
deleted file mode 100644 (file)
index aa707fb..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.trace;
-
-import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
-
-/**
- * <b><u>TmfStringLocation</u></b>
- * <p>
- * Implement me. Please.
- * <p>
- */
-public class TmfStringLocation extends TmfLocation {
-
-    /**
-     * @param location the concrete trace location
-     */
-    public TmfStringLocation(String location) {
-        super(location);
-    }
-
-    /**
-     * @param other the other location
-     */
-    public TmfStringLocation(TmfStringLocation other) {
-        super(other.getLocationInfo());
-    }
-
-    @Override
-    public String getLocationInfo() {
-        return (String) super.getLocationInfo();
-    }
-
-}
index c5303c17ec0205768015ecd29e22d4bab67953cc..6547f0f6377c8cd2d48148ce9f3834c769d46e27 100644 (file)
@@ -43,10 +43,10 @@ import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
 import org.junit.After;
 import org.junit.Before;
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/AllTests.java
new file mode 100644 (file)
index 0000000..0c5856a
--- /dev/null
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace.indexer.checkpoint;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite for org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    TmfCheckpointIndexTest.class,
+    TmfCheckpointIndexTest2.class,
+    TmfCheckpointTest.class,
+    TmfExperimentCheckpointIndexTest.class,
+})
+public class AllTests {}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfCheckpointIndexTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfCheckpointIndexTest.java
new file mode 100644 (file)
index 0000000..1cd80db
--- /dev/null
@@ -0,0 +1,194 @@
+/*******************************************************************************
+ * 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Adapted for TMF Trace Model 1.0
+ *   Alexandre Montplaisir - Port to JUnit4
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace.indexer.checkpoint;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfEmptyTraceStub;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the TmfCheckpointIndexTest class.
+ */
+@SuppressWarnings("javadoc")
+public class TmfCheckpointIndexTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private static final String    DIRECTORY   = "testfiles";
+    private static final String    TEST_STREAM = "A-Test-10K";
+    private static final int       BLOCK_SIZE  = 100;
+    private static final int       NB_EVENTS   = 10000;
+    private static TestTrace       fTrace      = null;
+    private static EmptyTestTrace  fEmptyTrace = null;
+
+    // ------------------------------------------------------------------------
+    // Housekeeping
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void setUp() {
+        setupTrace(DIRECTORY + File.separator + TEST_STREAM);
+    }
+
+    @After
+    public void tearDown() {
+        fTrace.dispose();
+        fTrace = null;
+        fEmptyTrace.dispose();
+        fEmptyTrace = null;
+    }
+
+    // ------------------------------------------------------------------------
+    // Helper classes
+    // ------------------------------------------------------------------------
+
+    private static class TestIndexer extends TmfCheckpointIndexer {
+        @SuppressWarnings({ })
+        public TestIndexer(TestTrace testTrace) {
+            super(testTrace, BLOCK_SIZE);
+        }
+        @SuppressWarnings({ })
+        public TestIndexer(EmptyTestTrace testTrace) {
+            super(testTrace, BLOCK_SIZE);
+        }
+        public List<ITmfCheckpoint> getCheckpoints() {
+            return getTraceIndex();
+        }
+    }
+
+    private class TestTrace extends TmfTraceStub {
+        public TestTrace(String path, int blockSize) throws TmfTraceException {
+            super(path, blockSize);
+            setIndexer(new TestIndexer(this));
+        }
+        @Override
+        public TestIndexer getIndexer() {
+            return (TestIndexer) super.getIndexer();
+        }
+    }
+
+    private class EmptyTestTrace extends TmfEmptyTraceStub {
+        public EmptyTestTrace() {
+            super();
+            setIndexer(new TestIndexer(this));
+        }
+        @Override
+        public TestIndexer getIndexer() {
+            return (TestIndexer) super.getIndexer();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Helper functions
+    // ------------------------------------------------------------------------
+
+    private synchronized void setupTrace(final String path) {
+        if (fTrace == null) {
+            try {
+                final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
+                final File test = new File(FileLocator.toFileURL(location).toURI());
+                fTrace = new TestTrace(test.toURI().getPath(), BLOCK_SIZE);
+                fTrace.indexTrace(true);
+            } catch (final TmfTraceException e) {
+                e.printStackTrace();
+            } catch (final URISyntaxException e) {
+                e.printStackTrace();
+            } catch (final IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        if (fEmptyTrace == null) {
+            fEmptyTrace = new EmptyTestTrace();
+            fEmptyTrace.indexTrace(true);
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Verify checkpoints
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testTmfTraceIndexing() {
+        assertEquals("getCacheSize",   BLOCK_SIZE, fTrace.getCacheSize());
+        assertEquals("getTraceSize",   NB_EVENTS,  fTrace.getNbEvents());
+        assertEquals("getRange-start", 1,          fTrace.getTimeRange().getStartTime().getValue());
+        assertEquals("getRange-end",   NB_EVENTS,  fTrace.getTimeRange().getEndTime().getValue());
+        assertEquals("getStartTime",   1,          fTrace.getStartTime().getValue());
+        assertEquals("getEndTime",     NB_EVENTS,  fTrace.getEndTime().getValue());
+
+        List<ITmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
+        int pageSize = fTrace.getCacheSize();
+        assertTrue("Checkpoints exist",  checkpoints != null);
+        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
+
+        // Validate that each checkpoint points to the right event
+        for (int i = 0; i < checkpoints.size(); i++) {
+            ITmfCheckpoint checkpoint = checkpoints.get(i);
+            TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
+            ITmfEvent event = fTrace.parseEvent(context);
+            assertTrue(context.getRank() == i * pageSize);
+            assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+        }
+    }
+
+    @Test
+    public void testEmptyTmfTraceIndexing() {
+        assertEquals("getCacheSize",   ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, fEmptyTrace.getCacheSize());
+        assertEquals("getTraceSize",   0,  fEmptyTrace.getNbEvents());
+        assertEquals("getRange-start", TmfTimestamp.BIG_BANG, fEmptyTrace.getTimeRange().getStartTime());
+        assertEquals("getRange-end",   TmfTimestamp.BIG_BANG, fEmptyTrace.getTimeRange().getEndTime());
+        assertEquals("getStartTime",   TmfTimestamp.BIG_BANG, fEmptyTrace.getStartTime());
+        assertEquals("getEndTime",     TmfTimestamp.BIG_BANG, fEmptyTrace.getEndTime());
+
+        List<ITmfCheckpoint> checkpoints = fEmptyTrace.getIndexer().getCheckpoints();
+        int pageSize = fEmptyTrace.getCacheSize();
+        assertTrue("Checkpoints exist",  checkpoints != null);
+        assertEquals("Checkpoints size", 0, checkpoints.size());
+
+        // Validate that each checkpoint points to the right event
+        for (int i = 0; i < checkpoints.size(); i++) {
+            ITmfCheckpoint checkpoint = checkpoints.get(i);
+            TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
+            ITmfEvent event = fEmptyTrace.parseEvent(context);
+            assertTrue(context.getRank() == i * pageSize);
+            assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfCheckpointIndexTest2.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfCheckpointIndexTest2.java
new file mode 100644 (file)
index 0000000..4d14603
--- /dev/null
@@ -0,0 +1,224 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Bernd Hufmann - Initial API and implementation
+ *   Alexandre Montplaisir - Port to JUnit4
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace.indexer.checkpoint;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfEmptyTraceStub;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the TmfCheckpointIndexer class (events with same
+ * timestamp around checkpoint).
+ */
+@SuppressWarnings("javadoc")
+public class TmfCheckpointIndexTest2 {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private static final String    DIRECTORY   = "testfiles";
+    // Trace has 3 events at t=101 at rank 99, 100, 101
+    // Trace has events with same timestamp (ts=102) for ranks 102..702 -> 2 checkpoints with same timestamp are created
+    private static final String    TEST_STREAM = "A-Test-10K-2";
+    private static final int       BLOCK_SIZE  = 100;
+    private static final int       NB_EVENTS   = 702;
+    private static TestTrace       fTrace      = null;
+    private static EmptyTestTrace  fEmptyTrace = null;
+
+    // ------------------------------------------------------------------------
+    // Housekeeping
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void setUp() {
+        setupTrace(DIRECTORY + File.separator + TEST_STREAM);
+    }
+
+    @After
+    public void tearDown() {
+        fTrace.dispose();
+        fTrace = null;
+        fEmptyTrace.dispose();
+        fEmptyTrace = null;
+    }
+
+    // ------------------------------------------------------------------------
+    // Helper classes
+    // ------------------------------------------------------------------------
+
+    private static class TestIndexer extends TmfCheckpointIndexer {
+        @SuppressWarnings({ })
+        public TestIndexer(TestTrace testTrace) {
+            super(testTrace, BLOCK_SIZE);
+        }
+        @SuppressWarnings({ })
+        public TestIndexer(EmptyTestTrace testTrace) {
+            super(testTrace, BLOCK_SIZE);
+        }
+        public List<ITmfCheckpoint> getCheckpoints() {
+            return getTraceIndex();
+        }
+    }
+
+    private class TestTrace extends TmfTraceStub {
+        public TestTrace(String path, int blockSize) throws TmfTraceException {
+            super(path, blockSize);
+            setIndexer(new TestIndexer(this));
+        }
+        @Override
+        public TestIndexer getIndexer() {
+            return (TestIndexer) super.getIndexer();
+        }
+    }
+
+    private class EmptyTestTrace extends TmfEmptyTraceStub {
+        public EmptyTestTrace() {
+            super();
+            setIndexer(new TestIndexer(this));
+        }
+        @Override
+        public TestIndexer getIndexer() {
+            return (TestIndexer) super.getIndexer();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Helper functions
+    // ------------------------------------------------------------------------
+
+    private synchronized void setupTrace(final String path) {
+        if (fTrace == null) {
+            try {
+                final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
+                final File test = new File(FileLocator.toFileURL(location).toURI());
+                fTrace = new TestTrace(test.toURI().getPath(), BLOCK_SIZE);
+                fTrace.indexTrace(true);
+            } catch (final TmfTraceException e) {
+                e.printStackTrace();
+            } catch (final URISyntaxException e) {
+                e.printStackTrace();
+            } catch (final IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        if (fEmptyTrace == null) {
+            fEmptyTrace = new EmptyTestTrace();
+            fEmptyTrace.indexTrace(true);
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Verify checkpoints
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testTmfTraceMultiTimestamps() {
+        assertEquals("getCacheSize",   BLOCK_SIZE, fTrace.getCacheSize());
+        assertEquals("getTraceSize",   NB_EVENTS,  fTrace.getNbEvents());
+        assertEquals("getRange-start", 1,          fTrace.getTimeRange().getStartTime().getValue());
+        assertEquals("getRange-end",   102,        fTrace.getTimeRange().getEndTime().getValue());
+        assertEquals("getStartTime",   1,          fTrace.getStartTime().getValue());
+        assertEquals("getEndTime",     102,        fTrace.getEndTime().getValue());
+
+        List<ITmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
+        assertTrue("Checkpoints exist",  checkpoints != null);
+        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE + 1, checkpoints.size());
+
+        // Trace has 3 events with same timestamp (ts=101) at rank 99, 100, 101
+
+        // Verify that the event at rank=99 is returned when seeking to ts=101 (first event with this timestamp)
+        // and not the event at checkpoint boundary
+        TmfTimestamp seekTs = new TmfTimestamp(101, -3, 0);
+        ITmfContext ctx = fTrace.seekEvent(seekTs);
+        ITmfEvent event = fTrace.getNext(ctx);
+
+        assertEquals(99, ctx.getRank());
+        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+        event = fTrace.getNext(ctx);
+
+        assertEquals(100, ctx.getRank());
+        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+        event = fTrace.getNext(ctx);
+
+        assertEquals(101, ctx.getRank());
+        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+        // Trace has events with same timestamp (ts=102) for ranks 102..702 -> 2 checkpoints with same timestamp are created
+        // Verify that the event at rank=102 is returned when seeking to ts=102 (first event with this timestamp)
+        // and not the event at checkpoint boundary
+        seekTs = new TmfTimestamp(102, -3, 0);
+        ctx = fTrace.seekEvent(seekTs);
+        event = fTrace.getNext(ctx);
+
+        assertEquals(102, ctx.getRank());
+        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+        // Verify seek to first checkpoint
+        seekTs = new TmfTimestamp(1, -3, 0);
+        ctx = fTrace.seekEvent(seekTs);
+        event = fTrace.getNext(ctx);
+
+        assertEquals(1, ctx.getRank());
+        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+        // Verify seek to timestamp before first event
+        seekTs = new TmfTimestamp(0, -3, 0);
+        ctx = fTrace.seekEvent(seekTs);
+        event = fTrace.getNext(ctx);
+
+        assertEquals(1, ctx.getRank());
+        assertEquals(0, new TmfTimestamp(1, -3, 0).compareTo(event.getTimestamp(), false));
+
+        // Verify seek to timestamp between first and second checkpoint
+        seekTs = new TmfTimestamp(50, -3, 0);
+        ctx = fTrace.seekEvent(seekTs);
+        event = fTrace.getNext(ctx);
+
+        assertEquals(50, ctx.getRank());
+        assertEquals(0, seekTs.compareTo(event.getTimestamp(), false));
+
+        // Verify seek to timestamp after last event in trace
+        seekTs = new TmfTimestamp(103, -3, 0);
+        ctx = fTrace.seekEvent(seekTs);
+        event = fTrace.getNext(ctx);
+
+        assertEquals(-1, ctx.getRank());
+        assertNull(event);
+    }
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfCheckpointTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfCheckpointTest.java
new file mode 100644 (file)
index 0000000..cb0871c
--- /dev/null
@@ -0,0 +1,239 @@
+/*******************************************************************************
+ * 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Adapted for TMF Trace Model 1.0
+ *   Alexandre Montplaisir - Port to JUnit4
+ *   Patrick Tasse - Updated for location in checkpoint
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace.indexer.checkpoint;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpoint;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
+import org.junit.Test;
+
+/**
+ * Test suite for the TmfCheckpoint class.
+ */
+@SuppressWarnings("javadoc")
+public class TmfCheckpointTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private ITmfTimestamp fTimestamp1 = new TmfTimestamp();
+    private ITmfTimestamp fTimestamp2 = TmfTimestamp.BIG_BANG;
+    private ITmfTimestamp fTimestamp3 = TmfTimestamp.BIG_CRUNCH;
+
+    private Long aLong1 = 12345L;
+    private Long aLong2 = 23456L;
+    private Long aLong3 = 34567L;
+    private ITmfLocation fLocation1 = new TmfLongLocation(aLong1);
+    private ITmfLocation fLocation2 = new TmfLongLocation(aLong2);
+    private ITmfLocation fLocation3 = new TmfLongLocation(aLong3);
+
+    private TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1);
+    private TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, fLocation2);
+    private TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, fLocation3);
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testTmfCheckpoint() {
+        assertEquals("TmfCheckpoint", fTimestamp1, fCheckpoint1.getTimestamp());
+        assertEquals("TmfCheckpoint", fLocation1,  fCheckpoint1.getLocation());
+    }
+
+    public void testTmfLocationCopy() {
+        final TmfCheckpoint checkpoint = new TmfCheckpoint(fCheckpoint1);
+
+        assertEquals("TmfCheckpoint", fTimestamp1, checkpoint.getTimestamp());
+        assertEquals("TmfCheckpoint", fLocation1,  checkpoint.getLocation());
+    }
+
+    @Test
+    public void testTmfLocationCopy2() {
+        try {
+            new TmfCheckpoint(null);
+            fail("null copy");
+        }
+        catch (final IllegalArgumentException e) {
+            // Success
+        }
+        catch (final Exception e) {
+            fail("wrong exception");
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // compareTo
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testCompareTo() {
+        assertEquals("compareTo",  0, fCheckpoint1.compareTo(fCheckpoint1));
+        assertEquals("compareTo",  1, fCheckpoint1.compareTo(fCheckpoint2));
+        assertEquals("compareTo", -1, fCheckpoint1.compareTo(fCheckpoint3));
+
+        assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint1));
+        assertEquals("compareTo",  0, fCheckpoint2.compareTo(fCheckpoint2));
+        assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint3));
+
+        assertEquals("compareTo",  1, fCheckpoint3.compareTo(fCheckpoint1));
+        assertEquals("compareTo",  1, fCheckpoint3.compareTo(fCheckpoint2));
+        assertEquals("compareTo",  0, fCheckpoint3.compareTo(fCheckpoint3));
+    }
+
+    @Test
+    public void testCompareToNull() {
+        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, fLocation1);
+        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(null, fLocation2);
+        final TmfCheckpoint checkpoint3 = new TmfCheckpoint(null, fLocation3);
+        final TmfCheckpoint checkpoint4 = new TmfCheckpoint(null, fLocation1);
+
+        // Test the various 'null' vs. '!null' combinations
+        assertEquals("compareTo",  0, checkpoint1.compareTo(fCheckpoint1));
+        assertEquals("compareTo",  0, fCheckpoint1.compareTo(checkpoint1));
+        assertEquals("compareTo", -1, checkpoint1.compareTo(fCheckpoint2));
+        assertEquals("compareTo",  1, fCheckpoint2.compareTo(checkpoint1));
+        assertEquals("compareTo", -1, checkpoint1.compareTo(fCheckpoint3));
+        assertEquals("compareTo",  1, fCheckpoint3.compareTo(checkpoint1));
+
+        // Test the 'null' vs. 'null' combinations
+        assertEquals("compareTo",  0, checkpoint1.compareTo(checkpoint4));
+        assertEquals("compareTo",  0, checkpoint4.compareTo(checkpoint1));
+        assertEquals("compareTo", -1, checkpoint1.compareTo(checkpoint2));
+        assertEquals("compareTo",  1, checkpoint2.compareTo(checkpoint1));
+        assertEquals("compareTo", -1, checkpoint1.compareTo(checkpoint3));
+        assertEquals("compareTo",  1, checkpoint3.compareTo(checkpoint1));
+    }
+
+    // ------------------------------------------------------------------------
+    // hashCode
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testHashCode() {
+        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1);
+        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2);
+
+        assertTrue("hashCode", fCheckpoint1.hashCode() == checkpoint1.hashCode());
+        assertTrue("hashCode", fCheckpoint2.hashCode() == checkpoint2.hashCode());
+
+        assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint2.hashCode());
+        assertTrue("hashCode", fCheckpoint2.hashCode() != checkpoint1.hashCode());
+    }
+
+    @Test
+    public void testHashCodeNull() {
+        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, fLocation1);
+        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp1, null);
+        final TmfCheckpoint checkpoint3 = new TmfCheckpoint(checkpoint1);
+        final TmfCheckpoint checkpoint4 = new TmfCheckpoint(checkpoint2);
+
+        assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint1.hashCode());
+        assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint2.hashCode());
+
+        assertTrue("hashCode", checkpoint1.hashCode() == checkpoint3.hashCode());
+        assertTrue("hashCode", checkpoint2.hashCode() == checkpoint4.hashCode());
+    }
+
+    // ------------------------------------------------------------------------
+    // equals
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testEqualsReflexivity() {
+        assertTrue("equals", fCheckpoint1.equals(fCheckpoint1));
+        assertTrue("equals", fCheckpoint2.equals(fCheckpoint2));
+
+        assertTrue("equals", !fCheckpoint1.equals(fCheckpoint2));
+        assertTrue("equals", !fCheckpoint2.equals(fCheckpoint1));
+    }
+
+    @Test
+    public void testEqualsSymmetry() {
+        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1);
+        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2);
+
+        assertTrue("equals", checkpoint1.equals(fCheckpoint1));
+        assertTrue("equals", fCheckpoint1.equals(checkpoint1));
+
+        assertTrue("equals", checkpoint2.equals(fCheckpoint2));
+        assertTrue("equals", fCheckpoint2.equals(checkpoint2));
+    }
+
+    @Test
+    public void testEqualsTransivity() {
+        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1);
+        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(checkpoint1);
+        final TmfCheckpoint checkpoint3 = new TmfCheckpoint(checkpoint2);
+
+        assertTrue("equals", checkpoint1.equals(checkpoint2));
+        assertTrue("equals", checkpoint2.equals(checkpoint3));
+        assertTrue("equals", checkpoint1.equals(checkpoint3));
+    }
+
+    @Test
+    public void testNotEqual() {
+        // Various checkpoints
+        final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1);
+        final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp2, fLocation1);
+        final TmfCheckpoint checkpoint3 = new TmfCheckpoint(fTimestamp1, fLocation2);
+        final TmfCheckpoint checkpoint4 = new TmfCheckpoint(fTimestamp1, null);
+        final TmfCheckpoint checkpoint5 = new TmfCheckpoint(null, fLocation1);
+
+        // Null check
+        assertFalse("equals", checkpoint1.equals(null));
+
+        // Different types
+        assertFalse("equals", checkpoint1.equals(new TmfTimestamp()));
+
+        // Null locations/location
+        assertFalse("equals", checkpoint1.equals(checkpoint4));
+        assertFalse("equals", checkpoint1.equals(checkpoint5));
+        assertFalse("equals", checkpoint4.equals(checkpoint1));
+        assertFalse("equals", checkpoint5.equals(checkpoint1));
+
+        // Different locations/location
+        assertFalse("equals", checkpoint1.equals(checkpoint2));
+        assertFalse("equals", checkpoint1.equals(checkpoint3));
+    }
+
+    // ------------------------------------------------------------------------
+    // toString
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testToString() {
+        final String expected1 = "TmfCheckpoint [fLocation=" + fCheckpoint1.getLocation() +
+                ", fTimestamp=" + fCheckpoint1.getTimestamp() + "]";
+        final String expected2 = "TmfCheckpoint [fLocation=" + fCheckpoint2.getLocation() +
+                ", fTimestamp=" + fCheckpoint2.getTimestamp() + "]";
+        final String expected3 = "TmfCheckpoint [fLocation=" + fCheckpoint3.getLocation() +
+                ", fTimestamp=" + fCheckpoint3.getTimestamp() + "]";
+
+        assertEquals("toString", expected1, fCheckpoint1.toString());
+        assertEquals("toString", expected2, fCheckpoint2.toString());
+        assertEquals("toString", expected3, fCheckpoint3.toString());
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfExperimentCheckpointIndexTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/indexer/checkpoint/TmfExperimentCheckpointIndexTest.java
new file mode 100644 (file)
index 0000000..3352aea
--- /dev/null
@@ -0,0 +1,194 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *   Alexandre Montplaisir - Port to JUnit4
+ *   Patrick Tasse - Updated for ranks in experiment location
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace.indexer.checkpoint;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the TmfCheckpointIndexTest class.
+ */
+@SuppressWarnings("javadoc")
+public class TmfExperimentCheckpointIndexTest {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private static final String DIRECTORY    = "testfiles";
+    private static final String TEST_STREAM1 = "O-Test-10K";
+    private static final String TEST_STREAM2 = "E-Test-10K";
+    private static final String EXPERIMENT   = "MyExperiment";
+    private static int          NB_EVENTS    = 20000;
+    private static int          BLOCK_SIZE   = 1000;
+
+    private static ITmfTrace[] fTestTraces;
+    private static TmfExperimentStub fExperiment;
+
+    // ------------------------------------------------------------------------
+    // Housekeeping
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void setUp() {
+        setupTraces();
+        fExperiment = new TmfExperimentStub(EXPERIMENT, fTestTraces, BLOCK_SIZE);
+        fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
+    }
+
+    @After
+    public void tearDown() {
+        fExperiment.dispose();
+        fExperiment = null;
+        for (ITmfTrace trace : fTestTraces) {
+            trace.dispose();
+        }
+        fTestTraces = null;
+    }
+
+    private static void setupTraces() {
+        final String path1 = DIRECTORY + File.separator + TEST_STREAM1;
+        final String path2 = DIRECTORY + File.separator + TEST_STREAM2;
+
+        fTestTraces = new ITmfTrace[2];
+        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);
+            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);
+            fTestTraces[1] = trace2;
+        } catch (final TmfTraceException e) {
+            e.printStackTrace();
+        } catch (final URISyntaxException e) {
+            e.printStackTrace();
+        } catch (final IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Verify checkpoints
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testTmfTraceIndexing() {
+        assertEquals("getCacheSize",   BLOCK_SIZE, fExperiment.getCacheSize());
+        assertEquals("getTraceSize",   NB_EVENTS,  fExperiment.getNbEvents());
+        assertEquals("getRange-start", 1,          fExperiment.getTimeRange().getStartTime().getValue());
+        assertEquals("getRange-end",   NB_EVENTS,  fExperiment.getTimeRange().getEndTime().getValue());
+        assertEquals("getStartTime",   1,          fExperiment.getStartTime().getValue());
+        assertEquals("getEndTime",     NB_EVENTS,  fExperiment.getEndTime().getValue());
+
+        List<ITmfCheckpoint> checkpoints = fExperiment.getIndexer().getCheckpoints();
+        int pageSize = fExperiment.getCacheSize();
+        assertTrue("Checkpoints exist",  checkpoints != null);
+        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
+
+        // Validate that each checkpoint points to the right event
+        for (int i = 0; i < checkpoints.size(); i++) {
+            ITmfCheckpoint checkpoint = checkpoints.get(i);
+            ITmfLocation location = checkpoint.getLocation();
+            ITmfContext context = fExperiment.seekEvent(location);
+            ITmfEvent event = fExperiment.parseEvent(context);
+            assertTrue(context.getRank() == i * pageSize);
+            assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Streaming
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testGrowingIndex() {
+        ITmfTrace[] testTraces = new TmfTraceStub[2];
+        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);
+            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);
+            testTraces[1] = trace2;
+        } catch (final TmfTraceException e) {
+            e.printStackTrace();
+        } catch (final URISyntaxException e) {
+            e.printStackTrace();
+        } catch (final IOException e) {
+            e.printStackTrace();
+        }
+
+        TmfExperimentStub experiment = new TmfExperimentStub(EXPERIMENT, testTraces, BLOCK_SIZE);
+        int pageSize = experiment.getCacheSize();
+
+        // Build the first half of the index
+        TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(1, -3), new TmfTimestamp(NB_EVENTS / 2 - 1, -3));
+        experiment.getIndexer().buildIndex(0, range, true);
+
+        // Validate that each checkpoint points to the right event
+        List<ITmfCheckpoint> checkpoints = experiment.getIndexer().getCheckpoints();
+        assertTrue("Checkpoints exist",  checkpoints != null);
+        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE / 2, checkpoints.size());
+
+        // Build the second half of the index
+        experiment.getIndexer().buildIndex(NB_EVENTS / 2, TmfTimeRange.ETERNITY, true);
+
+        // Validate that each checkpoint points to the right event
+        assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
+        for (int i = 0; i < checkpoints.size(); i++) {
+            ITmfCheckpoint checkpoint = checkpoints.get(i);
+            ITmfLocation location = checkpoint.getLocation();
+            ITmfContext context = experiment.seekEvent(location);
+            ITmfEvent event = experiment.parseEvent(context);
+            assertTrue(context.getRank() == i * pageSize);
+            assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
+            assertEquals("Checkpoint value", i * pageSize + 1, checkpoint.getTimestamp().getValue());
+        }
+
+        /* Clean up (since we didn't use the class-specific fixtures) */
+        experiment.dispose();
+        for (ITmfTrace trace : testTraces) {
+            trace.dispose();
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/location/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/location/AllTests.java
new file mode 100644 (file)
index 0000000..3593f4c
--- /dev/null
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Adjusted for new Trace Model
+ *   Alexandre Montplaisir - Port to JUnit4
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace.location;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite for org.eclipse.linuxtools.tmf.core.trace.location
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    TmfLocationTest.class,
+})
+public class AllTests {}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/location/TmfLocationTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/location/TmfLocationTest.java
new file mode 100644 (file)
index 0000000..a7c51d1
--- /dev/null
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *   Alexandre Montplaisir - Port to JUnit4
+ *   Patrick Tasse - Add tests for TmfExperimentLocation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace.location;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation;
+import org.eclipse.linuxtools.internal.tmf.core.trace.TmfLocationArray;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfTimestampLocation;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test suite for the TmfLocation class.
+ */
+@SuppressWarnings("javadoc")
+public class TmfLocationTest {
+
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
+
+    private String aString = "some location";
+    private Long aLong = 12345L;
+    private TmfTimestamp aTimestamp = new TmfTimestamp();
+    private TmfLocationArray aLocationArray;
+
+    private TmfStringLocation fLocation1;
+    private TmfStringLocation fLocation2;
+    private TmfLongLocation fLocation3;
+    private TmfTimestampLocation fLocation4;
+    private TmfExperimentLocation fExpLocation;
+
+    // ------------------------------------------------------------------------
+    // Housekeeping
+    // ------------------------------------------------------------------------
+
+    @Before
+    public void setUp() {
+        fLocation1 = new TmfStringLocation((String) null);
+        fLocation2 = new TmfStringLocation(aString);
+        fLocation3 = new TmfLongLocation(aLong);
+        fLocation4 = new TmfTimestampLocation(aTimestamp);
+        aLocationArray = new TmfLocationArray(
+                new ITmfLocation[] { fLocation1, fLocation2, fLocation3, fLocation4 },
+                new long[] { 1, 2, 3, 4 }
+                );
+        fExpLocation = new TmfExperimentLocation(aLocationArray);
+    }
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testTmfLocation() {
+        assertNull("TmfLocation", fLocation1.getLocationInfo());
+        assertEquals("TmfLocation", aString, fLocation2.getLocationInfo());
+        assertEquals("TmfLocation", aLong, fLocation3.getLocationInfo());
+        assertEquals("TmfLocation", aTimestamp, fLocation4.getLocationInfo());
+        assertEquals("TmfLocation", aLocationArray, fExpLocation.getLocationInfo());
+    }
+
+    @Test
+    public void testTmfLocationCopy() {
+        TmfStringLocation location1 = new TmfStringLocation(fLocation1);
+        TmfStringLocation location2 = new TmfStringLocation(fLocation2);
+        TmfLongLocation location3 = new TmfLongLocation(fLocation3);
+        TmfTimestampLocation location4 = new TmfTimestampLocation(fLocation4);
+        TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation);
+
+        assertNull("TmfLocation", location1.getLocationInfo());
+        assertEquals("TmfLocation", aString, location2.getLocationInfo());
+        assertEquals("TmfLocation", aLong, location3.getLocationInfo());
+        assertEquals("TmfLocation", aTimestamp, location4.getLocationInfo());
+        assertEquals("TmfLocation", aLocationArray, expLocation.getLocationInfo());
+    }
+
+    // ------------------------------------------------------------------------
+    // hashCode
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testHashCode() {
+        TmfStringLocation location1 = new TmfStringLocation((String) null);
+        TmfStringLocation location2 = new TmfStringLocation(aString);
+        TmfLongLocation location3 = new TmfLongLocation(aLong);
+        TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation);
+        TmfLocationArray locationArray1 = new TmfLocationArray(aLocationArray, 3, fLocation4, 5);
+        TmfExperimentLocation expLocation1 = new TmfExperimentLocation(locationArray1);
+        TmfLocationArray locationArray2 = new TmfLocationArray(aLocationArray, 3, fLocation3, 4);
+        TmfExperimentLocation expLocation2 = new TmfExperimentLocation(locationArray2);
+        TmfLocationArray locationArray3 = new TmfLocationArray(
+                new ITmfLocation[] { fLocation1, fLocation2, fLocation3 },
+                new long[] { 1, 2, 3 }
+                );
+        TmfExperimentLocation expLocation3 = new TmfExperimentLocation(locationArray3);
+
+        assertTrue("hashCode", fLocation1.hashCode() == location1.hashCode());
+        assertTrue("hashCode", fLocation2.hashCode() == location2.hashCode());
+        assertTrue("hashCode", fLocation3.hashCode() == location3.hashCode());
+        assertTrue("hashCode", fExpLocation.hashCode() == expLocation.hashCode());
+
+        assertTrue("hashCode", fLocation2.hashCode() != location3.hashCode());
+        assertTrue("hashCode", fLocation3.hashCode() != location2.hashCode());
+        assertTrue("hashCode", fExpLocation.hashCode() != expLocation1.hashCode());
+        assertTrue("hashCode", fExpLocation.hashCode() != expLocation2.hashCode());
+        assertTrue("hashCode", fExpLocation.hashCode() != expLocation3.hashCode());
+    }
+
+    // ------------------------------------------------------------------------
+    // toEquals
+    // ------------------------------------------------------------------------
+
+    private static class TmfLocation2 extends TmfStringLocation {
+        public TmfLocation2(String location) {
+            super(location);
+        }
+    }
+
+    @Test
+    public void testEqualsWrongTypes() {
+        ITmfLocation location1 = new TmfStringLocation(aString);
+        TmfLocation2 location2 = new TmfLocation2(aString);
+
+        assertFalse("equals", location1.equals(location2));
+        assertFalse("equals", location2.equals(location1));
+    }
+
+    @Test
+    public void testEqualsWithNulls() {
+        TmfStringLocation location1 = new TmfStringLocation(aString);
+        TmfStringLocation location2 = new TmfStringLocation((String) null);
+
+        assertFalse("equals", location1.equals(location2));
+        assertFalse("equals", location2.equals(location1));
+    }
+
+    @Test
+    public void testEqualsReflexivity() {
+        assertTrue("equals", fLocation2.equals(fLocation2));
+        assertTrue("equals", fLocation3.equals(fLocation3));
+        assertTrue("equals", fExpLocation.equals(fExpLocation));
+
+        assertTrue("equals", !fLocation2.equals(fLocation3));
+        assertTrue("equals", !fLocation3.equals(fLocation2));
+        TmfLocationArray locationArray1 = new TmfLocationArray(aLocationArray, 3, fLocation4, 5);
+        TmfExperimentLocation expLocation1 = new TmfExperimentLocation(locationArray1);
+        TmfLocationArray locationArray2 = new TmfLocationArray(aLocationArray, 3, fLocation3, 4);
+        TmfExperimentLocation expLocation2 = new TmfExperimentLocation(locationArray2);
+        TmfLocationArray locationArray3 = new TmfLocationArray(
+                new ITmfLocation[] { fLocation1, fLocation2, fLocation3 },
+                new long[] { 1, 2, 3 }
+                );
+        TmfExperimentLocation expLocation3 = new TmfExperimentLocation(locationArray3);
+        assertTrue("equals", !fExpLocation.equals(expLocation1));
+        assertTrue("equals", !expLocation1.equals(fExpLocation));
+        assertTrue("equals", !fExpLocation.equals(expLocation2));
+        assertTrue("equals", !expLocation2.equals(fExpLocation));
+        assertTrue("equals", !fExpLocation.equals(expLocation3));
+        assertTrue("equals", !expLocation3.equals(fExpLocation));
+    }
+
+    @Test
+    public void testEqualsSymmetry() {
+        TmfStringLocation location2 = new TmfStringLocation(aString);
+        TmfLongLocation location3 = new TmfLongLocation(aLong);
+        TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation);
+
+        assertTrue("equals", location2.equals(fLocation2));
+        assertTrue("equals", fLocation2.equals(location2));
+
+        assertTrue("equals", location3.equals(fLocation3));
+        assertTrue("equals", fLocation3.equals(location3));
+
+        assertTrue("equals", expLocation.equals(fExpLocation));
+        assertTrue("equals", fExpLocation.equals(expLocation));
+    }
+
+    @Test
+    public void testEqualsTransivity() {
+        TmfStringLocation location1 = new TmfStringLocation(aString);
+        TmfStringLocation location2 = new TmfStringLocation(aString);
+        TmfStringLocation location3 = new TmfStringLocation(aString);
+        TmfExperimentLocation expLocation1 = new TmfExperimentLocation(aLocationArray);
+        TmfExperimentLocation expLocation2 = new TmfExperimentLocation(aLocationArray);
+        TmfExperimentLocation expLocation3 = new TmfExperimentLocation(aLocationArray);
+
+        assertTrue("equals", location1.equals(location2));
+        assertTrue("equals", location2.equals(location3));
+        assertTrue("equals", location3.equals(location1));
+        assertTrue("equals", expLocation1.equals(expLocation2));
+        assertTrue("equals", expLocation2.equals(expLocation3));
+        assertTrue("equals", expLocation3.equals(expLocation1));
+    }
+
+    @Test
+    public void testEqualsNull() {
+        assertTrue("equals", !fLocation2.equals(null));
+        assertTrue("equals", !fLocation2.equals(null));
+        assertTrue("equals", !fExpLocation.equals(null));
+    }
+
+    // ------------------------------------------------------------------------
+    // toString
+    // ------------------------------------------------------------------------
+
+    @Test
+    public void testToString() {
+        String str = "some location";
+        Long lng = 12345L;
+        TmfTimestamp ts = new TmfTimestamp();
+
+        TmfStringLocation location1 = new TmfStringLocation(str);
+        TmfLongLocation location2 = new TmfLongLocation(lng);
+        TmfTimestampLocation location3 = new TmfTimestampLocation(ts);
+        TmfExperimentLocation expLocation = new TmfExperimentLocation(aLocationArray);
+
+        String expected1 = "TmfStringLocation [fLocationInfo=" + str + "]";
+        String expected2 = "TmfLongLocation [fLocationInfo=" + lng + "]";
+        String expected3 = "TmfTimestampLocation [fLocationInfo=" + ts + "]";
+        String expected4 = "TmfExperimentLocation [" + aLocationArray + "]";
+
+        assertEquals("toString", expected1, location1.toString());
+        assertEquals("toString", expected2, location2.toString());
+        assertEquals("toString", expected3, location3.toString());
+        assertEquals("toString", expected4, expLocation.toString());
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/location/TmfStringLocation.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/location/TmfStringLocation.java
new file mode 100644 (file)
index 0000000..fad258f
--- /dev/null
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.trace.location;
+
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLocation;
+
+/**
+ * <b><u>TmfStringLocation</u></b>
+ * <p>
+ * Implement me. Please.
+ * <p>
+ */
+public class TmfStringLocation extends TmfLocation {
+
+    /**
+     * @param location the concrete trace location
+     */
+    public TmfStringLocation(String location) {
+        super(location);
+    }
+
+    /**
+     * @param other the other location
+     */
+    public TmfStringLocation(TmfStringLocation other) {
+        super(other.getLocationInfo());
+    }
+
+    @Override
+    public String getLocationInfo() {
+        return (String) super.getLocationInfo();
+    }
+
+}
index 9c9e3210716a0134f2641e74ee68958cebda1671..3a5df51e0634ba7a58190b5c724417aa092cc4d5 100644 (file)
@@ -14,8 +14,8 @@ package org.eclipse.linuxtools.tmf.tests.stubs.trace;
 
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 /**
  * <b><u>TmfEmptyTraceStub</u></b>
index 1812d938f3f4efdc7613f2f883284ea89beed7da..a633f36b0a3c97544c485310d95af631164e2a82 100644 (file)
@@ -14,9 +14,9 @@ package org.eclipse.linuxtools.tmf.tests.stubs.trace;
 
 import java.util.List;
 
-import org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
 
 /**
  * <b><u>TmfIndexerStub</u></b>
index bac3cf0e5469a3a0d907beba24fa131bfbcf974b..8b7b430fcad9445a34a68439a19afdc76316abf8 100644 (file)
@@ -29,12 +29,12 @@ 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>
index 0e3c67c9489edf3383b17540576d1620fa55b54e..4364e38caa35b9981abc8004f7a58e6908ff34d8 100644 (file)
@@ -38,5 +38,8 @@ Export-Package: org.eclipse.linuxtools.internal.tmf.core;x-friends:="org.eclipse
  org.eclipse.linuxtools.tmf.core.statistics,
  org.eclipse.linuxtools.tmf.core.timestamp,
  org.eclipse.linuxtools.tmf.core.trace,
+ org.eclipse.linuxtools.tmf.core.trace.indexer,
+ org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint,
+ org.eclipse.linuxtools.tmf.core.trace.location,
  org.eclipse.linuxtools.tmf.core.uml2sd,
  org.eclipse.linuxtools.tmf.core.util
index 459493b31584df2c48c1d7208ecccc5ca5401925..bbd7b650dfdcfbaf2624ac6461057f140538833f 100644 (file)
@@ -14,7 +14,7 @@
 
 package org.eclipse.linuxtools.internal.tmf.core.trace;
 
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 
 /**
index 13deef2d00934425e74d6aa844f357dd93f66bd6..d0f5c38b6e2bdcc5634b71c94e2444c648b9c55b 100644 (file)
@@ -16,7 +16,7 @@ package org.eclipse.linuxtools.internal.tmf.core.trace;
 
 import java.util.Arrays;
 
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 
 /**
index 8311e7acb8fc351abd3183feab786cb491110e6f..9635d55a68481cdcd96f205b892e58bc95b7b23d 100644 (file)
@@ -13,7 +13,7 @@ package org.eclipse.linuxtools.tmf.core.ctfadaptor;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
 import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 /**
  * The CTF trace reader iterator.
@@ -202,6 +202,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
     /**
      * Method setLocation.
      * @param location ITmfLocation<?>
+     * @since 3.0
      */
     @Override
     public void setLocation(final ITmfLocation location) {
index 6cb87d918ffe02be71e1c26a2aa76ed345305794..b310f822c81eb433697b861498e3a631c88f7817 100644 (file)
@@ -13,7 +13,7 @@
 package org.eclipse.linuxtools.tmf.core.ctfadaptor;
 
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLocation;
 
 /**
  * The nugget of information that is unique to a location in a CTF trace.
index b1ef6d79559a2f8479c37527276aafb2570815e9..50278cbba445f9333a2ffb5dbd2d8b89a16c6358 100644 (file)
@@ -12,7 +12,7 @@
 package org.eclipse.linuxtools.tmf.core.ctfadaptor;
 
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 /**
  * Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to
@@ -58,6 +58,9 @@ public class CtfTmfContext implements ITmfContext {
         return curRank;
     }
 
+    /**
+     * @since 3.0
+     */
     @Override
     public ITmfLocation getLocation() {
         return curLocation;
@@ -68,6 +71,9 @@ public class CtfTmfContext implements ITmfContext {
         return curRank != CtfLocation.INVALID_LOCATION.getTimestamp();
     }
 
+    /**
+     * @since 3.0
+     */
     @Override
     public void setLocation(ITmfLocation location) {
         curLocation = (CtfLocation) location;
index 89151ee3db21807fa199361ec698eb029d97d189..844052beb2861aa7c54cd879c719619b55e557bc 100644 (file)
@@ -33,9 +33,9 @@ import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 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.ITmfTraceProperties;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 /**
  * The CTf trace handler
@@ -173,12 +173,16 @@ public class CtfTmfTrace extends TmfTrace
      *
      * @return null, since the trace has no knowledge of the current location
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentLocation()
+     * @since 3.0
      */
     @Override
     public ITmfLocation getCurrentLocation() {
         return null;
     }
 
+    /**
+     * @since 3.0
+     */
     @Override
     public double getLocationRatio(ITmfLocation location) {
         final CtfLocation curLocation = (CtfLocation) location;
@@ -198,6 +202,7 @@ public class CtfTmfTrace extends TmfTrace
      * @param location
      *            ITmfLocation<?>
      * @return ITmfContext
+     * @since 3.0
      */
     @Override
     public synchronized ITmfContext seekEvent(final ITmfLocation location) {
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfCheckpoint.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfCheckpoint.java
deleted file mode 100644 (file)
index e2e4e1b..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *   Patrick Tasse - Updated for location in checkpoint
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.trace;
-
-import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
-
-/**
- * The basic trace checkpoint structure in TMF. The purpose of the checkpoint is
- * to associate a trace location to an event timestamp.
- *
- * @version 1.0
- * @author Francois Chouinard
- *
- * @see ITmfTimestamp
- * @see ITmfLocation
- */
-public interface ITmfCheckpoint extends Comparable<ITmfCheckpoint> {
-
-    // ------------------------------------------------------------------------
-    // Getters
-    // ------------------------------------------------------------------------
-
-    /**
-     * @return the timestamp of the event referred to by the context
-     * @since 2.0
-     */
-    ITmfTimestamp getTimestamp();
-
-    /**
-     * @return the location of the event referred to by the checkpoint
-     */
-    ITmfLocation getLocation();
-
-    // ------------------------------------------------------------------------
-    // Comparable
-    // ------------------------------------------------------------------------
-
-    @Override
-    int compareTo(ITmfCheckpoint checkpoint);
-
-}
index 5413d9b8dac53ea811923c50d5afc00de9b2672d..f3b526e117e2771fcc5eaea1cadaaadf3ba175a4 100644 (file)
@@ -14,6 +14,8 @@
 
 package org.eclipse.linuxtools.tmf.core.trace;
 
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+
 /**
  * The basic trace context structure in TMF. The purpose of the context is to
  * associate a trace location to an event at a specific rank (order).
@@ -49,6 +51,7 @@ public interface ITmfContext {
 
     /**
      * @return the location of the event at the context rank
+     * @since 3.0
      */
     ITmfLocation getLocation();
 
@@ -63,6 +66,7 @@ public interface ITmfContext {
 
     /**
      * @param location the new location
+     * @since 3.0
      */
     void setLocation(ITmfLocation location);
 
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java
deleted file mode 100644 (file)
index 3f7b527..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2012 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *   Francois Chouinard - Updated as per TMF Trace Model 1.0
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.trace;
-
-/**
- * The generic trace location in TMF.
- * <p>
- * An ITmfLocation is the equivalent of a random-access file position, holding
- * enough information to allow the positioning of the trace 'pointer' to read an
- * arbitrary event.
- * <p>
- * This location is trace-specific, must be comparable and immutable.
- *
- * @version 2.0
- * @author Francois Chouinard
- */
-public interface ITmfLocation {
-
-    // ------------------------------------------------------------------------
-    // Getters
-    // ------------------------------------------------------------------------
-
-    /**
-     * Returns the concrete trace location information
-     *
-     * @return the location information
-     * @since 2.0
-     */
-    Comparable<?> getLocationInfo();
-
-}
index 1e680af5c2ec704dfd0473e3e8430556937e48fd..6abe83791b6bf10caa3a3710d952cfef11020784 100644 (file)
@@ -26,6 +26,8 @@ import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
 import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 /**
  * The event stream structure in TMF. In its basic form, a trace has:
@@ -259,6 +261,7 @@ public interface ITmfTrace extends ITmfDataProvider {
 
     /**
      * @return the current trace location
+     * @since 3.0
      */
     ITmfLocation getCurrentLocation();
 
@@ -267,6 +270,7 @@ public interface ITmfTrace extends ITmfDataProvider {
      *
      * @param location a trace specific location
      * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
+     * @since 3.0
      */
     double getLocationRatio(ITmfLocation location);
 
@@ -285,6 +289,7 @@ public interface ITmfTrace extends ITmfDataProvider {
      * <p>
      * @param location the trace specific location
      * @return a context which can later be used to read the corresponding event
+     * @since 3.0
      */
     ITmfContext seekEvent(ITmfLocation location);
 
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceIndexer.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceIndexer.java
deleted file mode 100644 (file)
index a36b3e0..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.trace;
-
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
-
-/**
- * The generic trace indexer in TMF with support for incremental indexing.
- *
- * @version 1.0
- * @author Francois Chouinard
- *
- * @see ITmfTrace
- * @see ITmfEvent
- */
-public interface ITmfTraceIndexer {
-
-    /**
-     * Start an asynchronous index building job and waits for the job completion
-     * if required. Typically, the indexing job sends notifications at regular
-     * intervals to indicate its progress.
-     * <p>
-     * <b>Example 1</b>: Index a whole trace asynchronously
-     *
-     * <pre>
-     * trace.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, false);
-     * </pre>
-     *
-     * <b>Example 2</b>: Index a whole trace synchronously
-     *
-     * <pre>
-     * trace.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
-     * </pre>
-     *
-     * <b>Example 3</b>: Index a trace asynchronously, starting at rank 100
-     *
-     * <pre>
-     * trace.getIndexer().buildIndex(100, TmfTimeRange.ETERNITY, false);
-     * </pre>
-     *
-     * <b>Example 4</b>: Index a trace asynchronously, starting at rank 100 for
-     * events between T1 and T2 (inclusive). This is used for incremental
-     * indexing.
-     *
-     * <pre>
-     * TmfTimeRange range = new TmfTimeRange(T1, T2);
-     * trace.getIndexer().buildIndex(100, range, false);
-     * </pre>
-     *
-     * @param offset
-     *            The offset of the first event to consider
-     * @param range
-     *            The time range to consider
-     * @param waitForCompletion
-     *            Should we block the calling thread until the build is
-     *            complete?
-     * @since 2.0
-     */
-    void buildIndex(long offset, TmfTimeRange range, boolean waitForCompletion);
-
-    /**
-     * Indicates that the indexer is busy indexing the trace.
-     * Will always return false if the indexing is done synchronously.
-     *
-     * @return the state of the indexer (indexing or not)
-     */
-    boolean isIndexing();
-
-    /**
-     * Adds an entry to the trace index.
-     *
-     * @param context The trace context to save
-     * @param timestamp The timestamp matching this context
-     * @since 2.0
-     */
-    void updateIndex(ITmfContext context, ITmfTimestamp timestamp);
-
-    /**
-     * Returns the context of the checkpoint immediately preceding the requested
-     * timestamp (or at the timestamp if it coincides with a checkpoint).
-     *
-     * @param timestamp the requested timestamp
-     * @return the checkpoint context
-     * @since 2.0
-     */
-    ITmfContext seekIndex(ITmfTimestamp timestamp);
-
-    /**
-     * Returns the context of the checkpoint immediately preceding the requested
-     * rank (or at rank if it coincides with a checkpoint).
-     *
-     * @param rank the requested event rank
-     * @return the checkpoint context
-     */
-    ITmfContext seekIndex(long rank);
-
-    /**
-     * Perform cleanup when the indexer is no longer required.
-     */
-    void dispose();
-
-}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpoint.java
deleted file mode 100644 (file)
index 9c93ddc..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/*******************************************************************************
- * 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *   Francois Chouinard - Updated as per TMF Trace Model 1.0
- *   Patrick Tasse - Updated for location in checkpoint
- ******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.trace;
-
-import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
-
-/**
- * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
- * to a generic location.
- *
- * @version 1.0
- * @author Francois Chouinard
- *
- * @see ITmfLocation
- * @see ITmfTimestamp
- */
-public class TmfCheckpoint implements ITmfCheckpoint {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    // The checkpoint location
-    private final ITmfLocation fLocation;
-
-    // The checkpoint timestamp
-    private final ITmfTimestamp fTimestamp;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Full constructor
-     *
-     * @param timestamp the checkpoint timestamp
-     * @param location the corresponding trace location
-     * @since 2.0
-     */
-    public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation location) {
-        fTimestamp = timestamp;
-        fLocation = location;
-    }
-
-    /**
-     * Copy constructor
-     *
-     * @param other the other checkpoint
-     */
-    public TmfCheckpoint(final TmfCheckpoint other) {
-        if (other == null) {
-            throw new IllegalArgumentException();
-        }
-        fTimestamp = other.fTimestamp;
-        fLocation = other.fLocation;
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfCheckpoint
-    // ------------------------------------------------------------------------
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public ITmfTimestamp getTimestamp() {
-        return fTimestamp;
-    }
-
-    @Override
-    public ITmfLocation getLocation() {
-        return fLocation;
-    }
-
-    // ------------------------------------------------------------------------
-    // Comparable
-    // ------------------------------------------------------------------------
-
-    @Override
-    @SuppressWarnings({ "unchecked", "rawtypes" })
-    public int compareTo(final ITmfCheckpoint other) {
-        int comp = 0;
-        if ((fTimestamp != null) && (other.getTimestamp() != null)) {
-            comp = fTimestamp.compareTo(other.getTimestamp(), false);
-            if (comp != 0) {
-                return comp;
-            }
-            // compare locations if timestamps are the same
-        }
-
-        if ((fLocation == null) && (other.getLocation() == null)) {
-            return 0;
-        }
-
-        // treat location of other as null location which is before any location
-        if ((fLocation != null) && (other.getLocation() == null)) {
-            return 1;
-        }
-
-        // treat this as null location which is before any other locations
-        if ((fLocation == null) && (other.getLocation() != null)) {
-            return -1;
-        }
-
-        // compare location
-        final Comparable location1 = getLocation().getLocationInfo();
-        final Comparable location2 = other.getLocation().getLocationInfo();
-        return location1.compareTo(location2);
-    }
-
-    // ------------------------------------------------------------------------
-    // Object
-    // ------------------------------------------------------------------------
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
-        result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (!(obj instanceof TmfCheckpoint)) {
-            return false;
-        }
-        final TmfCheckpoint other = (TmfCheckpoint) obj;
-        if (fLocation == null) {
-            if (other.fLocation != null) {
-                return false;
-            }
-        } else if (!fLocation.equals(other.fLocation)) {
-            return false;
-        }
-        if (fTimestamp == null) {
-            if (other.fTimestamp != null) {
-                return false;
-            }
-        } else if (!fTimestamp.equals(other.fTimestamp)) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    @SuppressWarnings("nls")
-    public String toString() {
-        return getClass().getSimpleName() + " [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]";
-    }
-
-}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java
deleted file mode 100644 (file)
index 8171bdd..0000000
+++ /dev/null
@@ -1,320 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.trace;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.linuxtools.internal.tmf.core.Messages;
-import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
-import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
-
-/**
- * A simple indexer that manages the trace index as an array of trace
- * checkpoints. Checkpoints are stored at fixed intervals (event rank) in
- * ascending timestamp order.
- * <p>
- * The goal being to access a random trace event reasonably fast from the user's
- * standpoint, picking the right interval value becomes a trade-off between speed
- * and memory usage (a shorter inter-event interval is faster but requires more
- * checkpoints).
- * <p>
- * Locating a specific checkpoint is trivial for both rank (rank % interval) and
- * timestamp (bsearch in the array).
- *
- * @version 1.0
- * @author Francois Chouinard
- *
- * @see ITmfTrace
- * @see ITmfEvent
- */
-public class TmfCheckpointIndexer implements ITmfTraceIndexer {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    /** The event trace to index */
-    protected final ITmfTrace fTrace;
-
-    /** The interval between checkpoints */
-    private final int fCheckpointInterval;
-
-    /** The event trace to index */
-    private boolean fIsIndexing;
-
-    /**
-     * The trace index. It is composed of checkpoints taken at intervals of
-     * fCheckpointInterval events.
-     */
-    protected final List<ITmfCheckpoint> fTraceIndex;
-
-    /**
-     * The indexing request
-     */
-    private ITmfEventRequest fIndexingRequest = null;
-
-    // ------------------------------------------------------------------------
-    // Construction
-    // ------------------------------------------------------------------------
-
-    /**
-     * Basic constructor that uses the default trace block size as checkpoints
-     * intervals
-     *
-     * @param trace the trace to index
-     */
-    public TmfCheckpointIndexer(final ITmfTrace trace) {
-        this(trace, TmfDataProvider.DEFAULT_BLOCK_SIZE);
-    }
-
-    /**
-     * Full trace indexer
-     *
-     * @param trace the trace to index
-     * @param interval the checkpoints interval
-     */
-    public TmfCheckpointIndexer(final ITmfTrace trace, final int interval) {
-        fTrace = trace;
-        fCheckpointInterval = interval;
-        fTraceIndex = new ArrayList<ITmfCheckpoint>();
-        fIsIndexing = false;
-    }
-
-    @Override
-    public void dispose() {
-        if ((fIndexingRequest != null) && !fIndexingRequest.isCompleted()) {
-            fIndexingRequest.cancel();
-            fTraceIndex.clear();
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfTraceIndexer - isIndexing
-    // ------------------------------------------------------------------------
-
-    @Override
-    public boolean isIndexing() {
-        return fIsIndexing;
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfTraceIndexer - buildIndex
-    // ------------------------------------------------------------------------
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public void buildIndex(final long offset, final TmfTimeRange range, final boolean waitForCompletion) {
-
-        // Don't do anything if we are already indexing
-        synchronized (fTraceIndex) {
-            if (fIsIndexing) {
-                return;
-            }
-            fIsIndexing = true;
-        }
-
-        // The monitoring job
-        final Job job = new Job("Indexing " + fTrace.getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$
-            @Override
-            protected IStatus run(final IProgressMonitor monitor) {
-                monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$
-                while (!monitor.isCanceled()) {
-                    try {
-                        long prevNbEvents = fTrace.getNbEvents();
-                        Thread.sleep(250);
-                        long nbEvents = fTrace.getNbEvents();
-                        setName(Messages.TmfCheckpointIndexer_Indexing + ' ' + fTrace.getName() + " (" + nbEvents + ")"); //$NON-NLS-1$ //$NON-NLS-2$
-                        // setName doesn't refresh the UI, setTaskName does
-                        long rate = (nbEvents - prevNbEvents) * 4;
-                        monitor.setTaskName(rate + " " + Messages.TmfCheckpointIndexer_EventsPerSecond); //$NON-NLS-1$
-                    } catch (final InterruptedException e) {
-                        return Status.OK_STATUS;
-                    }
-                }
-                monitor.done();
-                return Status.OK_STATUS;
-            }
-        };
-        job.schedule();
-
-        // Build a background request for all the trace data. The index is
-        // updated as we go by readNextEvent().
-        fIndexingRequest = new TmfEventRequest(ITmfEvent.class,
-                range, offset, TmfDataRequest.ALL_DATA,
-                ITmfDataRequest.ExecutionType.BACKGROUND) {
-            @Override
-            public void handleData(final ITmfEvent event) {
-                super.handleData(event);
-                if (event != null) {
-                    // Update the trace status at regular intervals
-                    if ((getNbRead() % fCheckpointInterval) == 0) {
-                        updateTraceStatus();
-                    }
-                }
-            }
-
-            @Override
-            public void handleSuccess() {
-                updateTraceStatus();
-            }
-
-            @Override
-            public void handleCompleted() {
-                job.cancel();
-                super.handleCompleted();
-                fIsIndexing = false;
-            }
-
-            private void updateTraceStatus() {
-                if (fTrace.getNbEvents() > 0) {
-                    signalNewTimeRange(fTrace.getStartTime(), fTrace.getEndTime());
-                }
-            }
-        };
-
-        // Submit the request and wait for completion if required
-        fTrace.sendRequest(fIndexingRequest);
-        if (waitForCompletion) {
-            try {
-                fIndexingRequest.waitForCompletion();
-            } catch (final InterruptedException e) {
-            }
-        }
-    }
-
-    /**
-     * Notify the interested parties that the trace time range has changed
-     *
-     * @param startTime the new start time
-     * @param endTime the new end time
-     */
-    private void signalNewTimeRange(final ITmfTimestamp startTime, final ITmfTimestamp endTime) {
-        fTrace.broadcast(new TmfTraceUpdatedSignal(fTrace, fTrace, new TmfTimeRange(startTime, endTime)));
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfTraceIndexer - updateIndex
-    // ------------------------------------------------------------------------
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) {
-        if ((context.getRank() % fCheckpointInterval) == 0) {
-            // Determine the table position
-            final long position = context.getRank() / fCheckpointInterval;
-            // Add new entry at proper location (if empty)
-            if (fTraceIndex.size() == position) {
-                fTraceIndex.add(new TmfCheckpoint(timestamp, context.getLocation()));
-            }
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfTraceIndexer - seekIndex
-    // ------------------------------------------------------------------------
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public synchronized ITmfContext seekIndex(final ITmfTimestamp timestamp) {
-
-        // A null timestamp indicates to seek the first event
-        if (timestamp == null) {
-            return fTrace.seekEvent(0);
-        }
-
-        // Find the checkpoint at or before the requested timestamp.
-        // In the very likely event that the timestamp is not at a checkpoint
-        // boundary, bsearch will return index = (- (insertion point + 1)).
-        // It is then trivial to compute the index of the previous checkpoint.
-        int index = Collections.binarySearch(fTraceIndex, new TmfCheckpoint(timestamp, null));
-        if (index < 0) {
-            index = Math.max(0, -(index + 2));
-        } else {
-            // If timestamp was in the list, use previous index to be able to find the
-            // first event with the same timestamp before the checkpoint
-            index = Math.max(0, index - 1);
-        }
-
-        // Position the trace at the checkpoint
-        return restoreCheckpoint(index);
-    }
-
-    @Override
-    public ITmfContext seekIndex(final long rank) {
-
-        // A rank < 0 indicates to seek the first event
-        if (rank < 0) {
-            return fTrace.seekEvent(0);
-        }
-
-        // Find the checkpoint at or before the requested rank.
-        final int index = (int) rank / fCheckpointInterval;
-
-        // Position the trace at the checkpoint
-        return restoreCheckpoint(index);
-    }
-
-    /**
-     * Position the trace at the given checkpoint
-     *
-     * @param checkpoint the checkpoint index
-     * @return the corresponding context
-     */
-    private ITmfContext restoreCheckpoint(final int checkpoint) {
-        ITmfLocation location = null;
-        int index = 0;
-        synchronized (fTraceIndex) {
-            if (!fTraceIndex.isEmpty()) {
-                index = checkpoint;
-                if (index >= fTraceIndex.size()) {
-                    index = fTraceIndex.size() - 1;
-                }
-                location = fTraceIndex.get(index).getLocation();
-            }
-        }
-        final ITmfContext context = fTrace.seekEvent(location);
-        context.setRank((long) index * fCheckpointInterval);
-        return context;
-    }
-
-    // ------------------------------------------------------------------------
-    // Getters
-    // ------------------------------------------------------------------------
-
-    /**
-     * @return the trace index
-     */
-    protected List<ITmfCheckpoint> getTraceIndex() {
-        return fTraceIndex;
-    }
-
-}
index 96a5b93c15806fab831e79b51101c24ff6c443e4..3b55ebe1ecb4c2384ecd18d99543e62a3c4f20d2 100644 (file)
@@ -14,6 +14,8 @@
 
 package org.eclipse.linuxtools.tmf.core.trace;
 
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+
 /**
  * A basic implementation of ITmfContext.
  * <p>
@@ -52,6 +54,7 @@ public class TmfContext implements ITmfContext {
      * Simple constructor (unknown rank)
      *
      * @param location the event location
+     * @since 3.0
      */
     public TmfContext(final ITmfLocation location) {
         this(location, UNKNOWN_RANK);
@@ -62,6 +65,7 @@ public class TmfContext implements ITmfContext {
      *
      * @param location the event location
      * @param rank the event rank
+     * @since 3.0
      */
     public TmfContext(final ITmfLocation location, final long rank) {
         fLocation = location;
@@ -85,11 +89,17 @@ public class TmfContext implements ITmfContext {
     // ITmfContext
     // ------------------------------------------------------------------------
 
+    /**
+     * @since 3.0
+     */
     @Override
     public ITmfLocation getLocation() {
         return fLocation;
     }
 
+    /**
+     * @since 3.0
+     */
     @Override
     public void setLocation(final ITmfLocation location) {
         fLocation = location;
index fd36a951c8d13b38268eca6d1faea2ca486e7df7..8ecd7ed5da814b10788fa385d808c6b37ae6626b 100644 (file)
@@ -33,6 +33,8 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 /**
  * TmfExperiment presents a time-ordered, unified view of a set of ITmfTrace:s
@@ -254,6 +256,9 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser {
     // ITmfTrace trace positioning
     // ------------------------------------------------------------------------
 
+    /**
+     * @since 3.0
+     */
     @Override
     public synchronized ITmfContext seekEvent(final ITmfLocation location) {
         // Validate the location
@@ -306,6 +311,9 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser {
         return context;
     }
 
+    /**
+     * @since 3.0
+     */
     @Override
     public double getLocationRatio(final ITmfLocation location) {
         if (location instanceof TmfExperimentLocation) {
@@ -319,6 +327,9 @@ public class TmfExperiment extends TmfTrace implements ITmfEventParser {
         return 0.0;
     }
 
+    /**
+     * @since 3.0
+     */
     @Override
     public ITmfLocation getCurrentLocation() {
         // never used
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java
deleted file mode 100644 (file)
index 5c9bdd1..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*******************************************************************************
- * 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *   Francois Chouinard - Updated as per TMF Trace Model 1.0
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.trace;
-
-
-/**
- * A abstract implementation of ITmfLocation. The concrete classes must provide
- * comparable location information.
- *
- * @version 2.0
- * @author Francois Chouinard
- */
-public abstract class TmfLocation implements ITmfLocation {
-
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    private final Comparable<?> fLocationInfo;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Standard constructor.
-     *
-     * @param locationInfo
-     *            The concrete trace location
-     */
-    public TmfLocation(final Comparable<?> locationInfo) {
-        fLocationInfo = locationInfo;
-    }
-
-    /**
-     * Copy constructor
-     *
-     * @param location
-     *            The original trace location
-     */
-    public TmfLocation(final TmfLocation location) {
-        fLocationInfo = location.fLocationInfo;
-    }
-
-    // ------------------------------------------------------------------------
-    // Getters
-    // ------------------------------------------------------------------------
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public Comparable<?> getLocationInfo() {
-        return fLocationInfo;
-    }
-
-    // ------------------------------------------------------------------------
-    // Object
-    // ------------------------------------------------------------------------
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((fLocationInfo != null) ? fLocationInfo.hashCode() : 0);
-        return result;
-    }
-
-    @Override
-    public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        final TmfLocation other = (TmfLocation) obj;
-        if (fLocationInfo == null) {
-            if (other.fLocationInfo != null) {
-                return false;
-            }
-        } else if (!fLocationInfo.equals(other.fLocationInfo)) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    @SuppressWarnings("nls")
-    public String toString() {
-        return getClass().getSimpleName() + " [fLocationInfo=" + fLocationInfo + "]";
-    }
-
-}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLongLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLongLocation.java
deleted file mode 100644 (file)
index 905e372..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.trace;
-
-/**
- * A concrete implementation of TmfLocation based on Long:s
- *
- * @author Francois Chouinard
- * @since 2.0
- */
-public final class TmfLongLocation extends TmfLocation {
-
-    /**
-     * The normal constructor
-     *
-     * @param locationInfo the concrete location
-     */
-    public TmfLongLocation(final Long locationInfo) {
-        super(locationInfo);
-    }
-
-    /**
-     * The copy constructor
-     *
-     * @param other the other location
-     */
-    public TmfLongLocation(final TmfLongLocation other) {
-        super(other.getLocationInfo());
-    }
-
-    @Override
-    public Long getLocationInfo() {
-        return (Long) super.getLocationInfo();
-    }
-
-}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTimestampLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTimestampLocation.java
deleted file mode 100644 (file)
index 5136d6d..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.trace;
-
-import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
-
-/**
- * A concrete implementation of TmfLocation based on ITmfTimestamp:s
- *
- * @author Francois Chouinard
- * @since 2.0
- */
-public final class TmfTimestampLocation extends TmfLocation {
-
-    /**
-     * The normal constructor
-     *
-     * @param locationInfo the concrete location
-     */
-    public TmfTimestampLocation(final ITmfTimestamp locationInfo) {
-        super(locationInfo);
-    }
-
-    /**
-     * The copy constructor
-     *
-     * @param other the other location
-     */
-    public TmfTimestampLocation(final TmfTimestampLocation other) {
-        super(other.getLocationInfo());
-    }
-
-    @Override
-    public ITmfTimestamp getLocationInfo() {
-        return (ITmfTimestamp) super.getLocationInfo();
-    }
-
-}
index 65b871a50a03f9b1b3feae48a727d3a7cafbb1ab..817d85254701bcf6e7ad3143bbea4de063197804 100644 (file)
@@ -41,6 +41,9 @@ import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 /**
  * Abstract implementation of ITmfTrace.
@@ -340,6 +343,7 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
 
     /**
      * @return the trace indexer
+     * @since 3.0
      */
     protected ITmfTraceIndexer getIndexer() {
         return fIndexer;
@@ -493,6 +497,7 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
      * Set the trace indexer. Must be done at initialization time.
      *
      * @param indexer the trace indexer
+     * @since 3.0
      */
     protected void setIndexer(final ITmfTraceIndexer indexer) {
         fIndexer = indexer;
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/ITmfTraceIndexer.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/ITmfTraceIndexer.java
new file mode 100644 (file)
index 0000000..3f27948
--- /dev/null
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.trace.indexer;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+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.ITmfTrace;
+
+/**
+ * The generic trace indexer in TMF with support for incremental indexing.
+ *
+ * @see ITmfTrace
+ * @see ITmfEvent
+ *
+ * @author Francois Chouinard
+ * @since 3.0
+ */
+public interface ITmfTraceIndexer {
+
+    /**
+     * Start an asynchronous index building job and waits for the job completion
+     * if required. Typically, the indexing job sends notifications at regular
+     * intervals to indicate its progress.
+     * <p>
+     * <b>Example 1</b>: Index a whole trace asynchronously
+     *
+     * <pre>
+     * trace.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, false);
+     * </pre>
+     *
+     * <b>Example 2</b>: Index a whole trace synchronously
+     *
+     * <pre>
+     * trace.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
+     * </pre>
+     *
+     * <b>Example 3</b>: Index a trace asynchronously, starting at rank 100
+     *
+     * <pre>
+     * trace.getIndexer().buildIndex(100, TmfTimeRange.ETERNITY, false);
+     * </pre>
+     *
+     * <b>Example 4</b>: Index a trace asynchronously, starting at rank 100 for
+     * events between T1 and T2 (inclusive). This is used for incremental
+     * indexing.
+     *
+     * <pre>
+     * TmfTimeRange range = new TmfTimeRange(T1, T2);
+     * trace.getIndexer().buildIndex(100, range, false);
+     * </pre>
+     *
+     * @param offset
+     *            The offset of the first event to consider
+     * @param range
+     *            The time range to consider
+     * @param waitForCompletion
+     *            Should we block the calling thread until the build is
+     *            complete?
+     * @since 2.0
+     */
+    void buildIndex(long offset, TmfTimeRange range, boolean waitForCompletion);
+
+    /**
+     * Indicates that the indexer is busy indexing the trace.
+     * Will always return false if the indexing is done synchronously.
+     *
+     * @return the state of the indexer (indexing or not)
+     */
+    boolean isIndexing();
+
+    /**
+     * Adds an entry to the trace index.
+     *
+     * @param context The trace context to save
+     * @param timestamp The timestamp matching this context
+     * @since 2.0
+     */
+    void updateIndex(ITmfContext context, ITmfTimestamp timestamp);
+
+    /**
+     * Returns the context of the checkpoint immediately preceding the requested
+     * timestamp (or at the timestamp if it coincides with a checkpoint).
+     *
+     * @param timestamp the requested timestamp
+     * @return the checkpoint context
+     * @since 2.0
+     */
+    ITmfContext seekIndex(ITmfTimestamp timestamp);
+
+    /**
+     * Returns the context of the checkpoint immediately preceding the requested
+     * rank (or at rank if it coincides with a checkpoint).
+     *
+     * @param rank the requested event rank
+     * @return the checkpoint context
+     */
+    ITmfContext seekIndex(long rank);
+
+    /**
+     * Perform cleanup when the indexer is no longer required.
+     */
+    void dispose();
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/checkpoint/ITmfCheckpoint.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/checkpoint/ITmfCheckpoint.java
new file mode 100644 (file)
index 0000000..9dcb499
--- /dev/null
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *   Patrick Tasse - Updated for location in checkpoint
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint;
+
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+
+/**
+ * The basic trace checkpoint structure in TMF. The purpose of the checkpoint is
+ * to associate a trace location to an event timestamp.
+ * *
+ * @see ITmfTimestamp
+ * @see ITmfLocation
+ *
+ * @author Francois Chouinard
+ * @since 3.0
+ */
+public interface ITmfCheckpoint extends Comparable<ITmfCheckpoint> {
+
+    // ------------------------------------------------------------------------
+    // Getters
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the timestamp of the event referred to by the context
+     * @since 2.0
+     */
+    ITmfTimestamp getTimestamp();
+
+    /**
+     * @return the location of the event referred to by the checkpoint
+     */
+    ITmfLocation getLocation();
+
+    // ------------------------------------------------------------------------
+    // Comparable
+    // ------------------------------------------------------------------------
+
+    @Override
+    int compareTo(ITmfCheckpoint checkpoint);
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/checkpoint/TmfCheckpoint.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/checkpoint/TmfCheckpoint.java
new file mode 100644 (file)
index 0000000..e2d5624
--- /dev/null
@@ -0,0 +1,172 @@
+/*******************************************************************************
+ * 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Updated as per TMF Trace Model 1.0
+ *   Patrick Tasse - Updated for location in checkpoint
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint;
+
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+
+/**
+ * A basic implementation of ITmfCheckpoint. It simply maps an event timestamp
+ * to a generic location.
+ *
+ * @see ITmfLocation
+ * @see ITmfTimestamp
+ *
+ * @author Francois Chouinard
+ * @since 3.0
+ */
+public class TmfCheckpoint implements ITmfCheckpoint {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    // The checkpoint location
+    private final ITmfLocation fLocation;
+
+    // The checkpoint timestamp
+    private final ITmfTimestamp fTimestamp;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Full constructor
+     *
+     * @param timestamp the checkpoint timestamp
+     * @param location the corresponding trace location
+     * @since 3.0
+     */
+    public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation location) {
+        fTimestamp = timestamp;
+        fLocation = location;
+    }
+
+    /**
+     * Copy constructor
+     *
+     * @param other the other checkpoint
+     */
+    public TmfCheckpoint(final TmfCheckpoint other) {
+        if (other == null) {
+            throw new IllegalArgumentException();
+        }
+        fTimestamp = other.fTimestamp;
+        fLocation = other.fLocation;
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfCheckpoint
+    // ------------------------------------------------------------------------
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public ITmfTimestamp getTimestamp() {
+        return fTimestamp;
+    }
+
+    @Override
+    public ITmfLocation getLocation() {
+        return fLocation;
+    }
+
+    // ------------------------------------------------------------------------
+    // Comparable
+    // ------------------------------------------------------------------------
+
+    @Override
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    public int compareTo(final ITmfCheckpoint other) {
+        int comp = 0;
+        if ((fTimestamp != null) && (other.getTimestamp() != null)) {
+            comp = fTimestamp.compareTo(other.getTimestamp(), false);
+            if (comp != 0) {
+                return comp;
+            }
+            // compare locations if timestamps are the same
+        }
+
+        if ((fLocation == null) && (other.getLocation() == null)) {
+            return 0;
+        }
+
+        // treat location of other as null location which is before any location
+        if ((fLocation != null) && (other.getLocation() == null)) {
+            return 1;
+        }
+
+        // treat this as null location which is before any other locations
+        if ((fLocation == null) && (other.getLocation() != null)) {
+            return -1;
+        }
+
+        // compare location
+        final Comparable location1 = getLocation().getLocationInfo();
+        final Comparable location2 = other.getLocation().getLocationInfo();
+        return location1.compareTo(location2);
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
+        result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof TmfCheckpoint)) {
+            return false;
+        }
+        final TmfCheckpoint other = (TmfCheckpoint) obj;
+        if (fLocation == null) {
+            if (other.fLocation != null) {
+                return false;
+            }
+        } else if (!fLocation.equals(other.fLocation)) {
+            return false;
+        }
+        if (fTimestamp == null) {
+            if (other.fTimestamp != null) {
+                return false;
+            }
+        } else if (!fTimestamp.equals(other.fTimestamp)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        return getClass().getSimpleName() + " [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]";
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/checkpoint/TmfCheckpointIndexer.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/indexer/checkpoint/TmfCheckpointIndexer.java
new file mode 100644 (file)
index 0000000..18ddef9
--- /dev/null
@@ -0,0 +1,324 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.internal.tmf.core.Messages;
+import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
+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.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
+
+/**
+ * A simple indexer that manages the trace index as an array of trace
+ * checkpoints. Checkpoints are stored at fixed intervals (event rank) in
+ * ascending timestamp order.
+ * <p>
+ * The goal being to access a random trace event reasonably fast from the user's
+ * standpoint, picking the right interval value becomes a trade-off between speed
+ * and memory usage (a shorter inter-event interval is faster but requires more
+ * checkpoints).
+ * <p>
+ * Locating a specific checkpoint is trivial for both rank (rank % interval) and
+ * timestamp (bsearch in the array).
+ * *
+ * @see ITmfTrace
+ * @see ITmfEvent
+ *
+ * @author Francois Chouinard
+ * @since 3.0
+ */
+public class TmfCheckpointIndexer implements ITmfTraceIndexer {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /** The event trace to index */
+    protected final ITmfTrace fTrace;
+
+    /** The interval between checkpoints */
+    private final int fCheckpointInterval;
+
+    /** The event trace to index */
+    private boolean fIsIndexing;
+
+    /**
+     * The trace index. It is composed of checkpoints taken at intervals of
+     * fCheckpointInterval events.
+     */
+    protected final List<ITmfCheckpoint> fTraceIndex;
+
+    /**
+     * The indexing request
+     */
+    private ITmfEventRequest fIndexingRequest = null;
+
+    // ------------------------------------------------------------------------
+    // Construction
+    // ------------------------------------------------------------------------
+
+    /**
+     * Basic constructor that uses the default trace block size as checkpoints
+     * intervals
+     *
+     * @param trace the trace to index
+     */
+    public TmfCheckpointIndexer(final ITmfTrace trace) {
+        this(trace, TmfDataProvider.DEFAULT_BLOCK_SIZE);
+    }
+
+    /**
+     * Full trace indexer
+     *
+     * @param trace the trace to index
+     * @param interval the checkpoints interval
+     */
+    public TmfCheckpointIndexer(final ITmfTrace trace, final int interval) {
+        fTrace = trace;
+        fCheckpointInterval = interval;
+        fTraceIndex = new ArrayList<ITmfCheckpoint>();
+        fIsIndexing = false;
+    }
+
+    @Override
+    public void dispose() {
+        if ((fIndexingRequest != null) && !fIndexingRequest.isCompleted()) {
+            fIndexingRequest.cancel();
+            fTraceIndex.clear();
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfTraceIndexer - isIndexing
+    // ------------------------------------------------------------------------
+
+    @Override
+    public boolean isIndexing() {
+        return fIsIndexing;
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfTraceIndexer - buildIndex
+    // ------------------------------------------------------------------------
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public void buildIndex(final long offset, final TmfTimeRange range, final boolean waitForCompletion) {
+
+        // Don't do anything if we are already indexing
+        synchronized (fTraceIndex) {
+            if (fIsIndexing) {
+                return;
+            }
+            fIsIndexing = true;
+        }
+
+        // The monitoring job
+        final Job job = new Job("Indexing " + fTrace.getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$
+            @Override
+            protected IStatus run(final IProgressMonitor monitor) {
+                monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$
+                while (!monitor.isCanceled()) {
+                    try {
+                        long prevNbEvents = fTrace.getNbEvents();
+                        Thread.sleep(250);
+                        long nbEvents = fTrace.getNbEvents();
+                        setName(Messages.TmfCheckpointIndexer_Indexing + ' ' + fTrace.getName() + " (" + nbEvents + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+                        // setName doesn't refresh the UI, setTaskName does
+                        long rate = (nbEvents - prevNbEvents) * 4;
+                        monitor.setTaskName(rate + " " + Messages.TmfCheckpointIndexer_EventsPerSecond); //$NON-NLS-1$
+                    } catch (final InterruptedException e) {
+                        return Status.OK_STATUS;
+                    }
+                }
+                monitor.done();
+                return Status.OK_STATUS;
+            }
+        };
+        job.schedule();
+
+        // Build a background request for all the trace data. The index is
+        // updated as we go by readNextEvent().
+        fIndexingRequest = new TmfEventRequest(ITmfEvent.class,
+                range, offset, TmfDataRequest.ALL_DATA,
+                ITmfDataRequest.ExecutionType.BACKGROUND) {
+            @Override
+            public void handleData(final ITmfEvent event) {
+                super.handleData(event);
+                if (event != null) {
+                    // Update the trace status at regular intervals
+                    if ((getNbRead() % fCheckpointInterval) == 0) {
+                        updateTraceStatus();
+                    }
+                }
+            }
+
+            @Override
+            public void handleSuccess() {
+                updateTraceStatus();
+            }
+
+            @Override
+            public void handleCompleted() {
+                job.cancel();
+                super.handleCompleted();
+                fIsIndexing = false;
+            }
+
+            private void updateTraceStatus() {
+                if (fTrace.getNbEvents() > 0) {
+                    signalNewTimeRange(fTrace.getStartTime(), fTrace.getEndTime());
+                }
+            }
+        };
+
+        // Submit the request and wait for completion if required
+        fTrace.sendRequest(fIndexingRequest);
+        if (waitForCompletion) {
+            try {
+                fIndexingRequest.waitForCompletion();
+            } catch (final InterruptedException e) {
+            }
+        }
+    }
+
+    /**
+     * Notify the interested parties that the trace time range has changed
+     *
+     * @param startTime the new start time
+     * @param endTime the new end time
+     */
+    private void signalNewTimeRange(final ITmfTimestamp startTime, final ITmfTimestamp endTime) {
+        fTrace.broadcast(new TmfTraceUpdatedSignal(fTrace, fTrace, new TmfTimeRange(startTime, endTime)));
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfTraceIndexer - updateIndex
+    // ------------------------------------------------------------------------
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) {
+        if ((context.getRank() % fCheckpointInterval) == 0) {
+            // Determine the table position
+            final long position = context.getRank() / fCheckpointInterval;
+            // Add new entry at proper location (if empty)
+            if (fTraceIndex.size() == position) {
+                fTraceIndex.add(new TmfCheckpoint(timestamp, context.getLocation()));
+            }
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfTraceIndexer - seekIndex
+    // ------------------------------------------------------------------------
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public synchronized ITmfContext seekIndex(final ITmfTimestamp timestamp) {
+
+        // A null timestamp indicates to seek the first event
+        if (timestamp == null) {
+            return fTrace.seekEvent(0);
+        }
+
+        // Find the checkpoint at or before the requested timestamp.
+        // In the very likely event that the timestamp is not at a checkpoint
+        // boundary, bsearch will return index = (- (insertion point + 1)).
+        // It is then trivial to compute the index of the previous checkpoint.
+        int index = Collections.binarySearch(fTraceIndex, new TmfCheckpoint(timestamp, null));
+        if (index < 0) {
+            index = Math.max(0, -(index + 2));
+        } else {
+            // If timestamp was in the list, use previous index to be able to find the
+            // first event with the same timestamp before the checkpoint
+            index = Math.max(0, index - 1);
+        }
+
+        // Position the trace at the checkpoint
+        return restoreCheckpoint(index);
+    }
+
+    @Override
+    public ITmfContext seekIndex(final long rank) {
+
+        // A rank < 0 indicates to seek the first event
+        if (rank < 0) {
+            return fTrace.seekEvent(0);
+        }
+
+        // Find the checkpoint at or before the requested rank.
+        final int index = (int) rank / fCheckpointInterval;
+
+        // Position the trace at the checkpoint
+        return restoreCheckpoint(index);
+    }
+
+    /**
+     * Position the trace at the given checkpoint
+     *
+     * @param checkpoint the checkpoint index
+     * @return the corresponding context
+     */
+    private ITmfContext restoreCheckpoint(final int checkpoint) {
+        ITmfLocation location = null;
+        int index = 0;
+        synchronized (fTraceIndex) {
+            if (!fTraceIndex.isEmpty()) {
+                index = checkpoint;
+                if (index >= fTraceIndex.size()) {
+                    index = fTraceIndex.size() - 1;
+                }
+                location = fTraceIndex.get(index).getLocation();
+            }
+        }
+        final ITmfContext context = fTrace.seekEvent(location);
+        context.setRank((long) index * fCheckpointInterval);
+        return context;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the trace index
+     */
+    protected List<ITmfCheckpoint> getTraceIndex() {
+        return fTraceIndex;
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/ITmfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/ITmfLocation.java
new file mode 100644 (file)
index 0000000..1280723
--- /dev/null
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Updated as per TMF Trace Model 1.0
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.trace.location;
+
+/**
+ * The generic trace location in TMF.
+ * <p>
+ * An ITmfLocation is the equivalent of a random-access file position, holding
+ * enough information to allow the positioning of the trace 'pointer' to read an
+ * arbitrary event.
+ * <p>
+ * This location is trace-specific, must be comparable and immutable.
+ *
+ * @author Francois Chouinard
+ * @since 3.0
+ */
+public interface ITmfLocation {
+
+    // ------------------------------------------------------------------------
+    // Getters
+    // ------------------------------------------------------------------------
+
+    /**
+     * Returns the concrete trace location information
+     *
+     * @return the location information
+     * @since 2.0
+     */
+    Comparable<?> getLocationInfo();
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/TmfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/TmfLocation.java
new file mode 100644 (file)
index 0000000..133f002
--- /dev/null
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Updated as per TMF Trace Model 1.0
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.trace.location;
+
+
+/**
+ * A abstract implementation of ITmfLocation. The concrete classes must provide
+ * comparable location information.
+ *
+ * @author Francois Chouinard
+ * @since 3.0
+ */
+public abstract class TmfLocation implements ITmfLocation {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private final Comparable<?> fLocationInfo;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Standard constructor.
+     *
+     * @param locationInfo
+     *            The concrete trace location
+     */
+    public TmfLocation(final Comparable<?> locationInfo) {
+        fLocationInfo = locationInfo;
+    }
+
+    /**
+     * Copy constructor
+     *
+     * @param location
+     *            The original trace location
+     */
+    public TmfLocation(final TmfLocation location) {
+        fLocationInfo = location.fLocationInfo;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters
+    // ------------------------------------------------------------------------
+
+    /**
+     * @since 2.0
+     */
+    @Override
+    public Comparable<?> getLocationInfo() {
+        return fLocationInfo;
+    }
+
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((fLocationInfo != null) ? fLocationInfo.hashCode() : 0);
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final TmfLocation other = (TmfLocation) obj;
+        if (fLocationInfo == null) {
+            if (other.fLocationInfo != null) {
+                return false;
+            }
+        } else if (!fLocationInfo.equals(other.fLocationInfo)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    @SuppressWarnings("nls")
+    public String toString() {
+        return getClass().getSimpleName() + " [fLocationInfo=" + fLocationInfo + "]";
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/TmfLongLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/TmfLongLocation.java
new file mode 100644 (file)
index 0000000..38877ca
--- /dev/null
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.trace.location;
+
+
+/**
+ * A concrete implementation of TmfLocation based on Long:s
+ *
+ * @author Francois Chouinard
+ * @since 3.0
+ */
+public final class TmfLongLocation extends TmfLocation {
+
+    /**
+     * The normal constructor
+     *
+     * @param locationInfo the concrete location
+     */
+    public TmfLongLocation(final Long locationInfo) {
+        super(locationInfo);
+    }
+
+    /**
+     * The copy constructor
+     *
+     * @param other the other location
+     */
+    public TmfLongLocation(final TmfLongLocation other) {
+        super(other.getLocationInfo());
+    }
+
+    @Override
+    public Long getLocationInfo() {
+        return (Long) super.getLocationInfo();
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/TmfTimestampLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/location/TmfTimestampLocation.java
new file mode 100644 (file)
index 0000000..22c48f4
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.trace.location;
+
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+
+/**
+ * A concrete implementation of TmfLocation based on ITmfTimestamp:s
+ *
+ * @author Francois Chouinard
+ * @since 3.0
+ */
+public final class TmfTimestampLocation extends TmfLocation {
+
+    /**
+     * The normal constructor
+     *
+     * @param locationInfo the concrete location
+     */
+    public TmfTimestampLocation(final ITmfTimestamp locationInfo) {
+        super(locationInfo);
+    }
+
+    /**
+     * The copy constructor
+     *
+     * @param other the other location
+     */
+    public TmfTimestampLocation(final TmfTimestampLocation other) {
+        super(other.getLocationInfo());
+    }
+
+    @Override
+    public ITmfTimestamp getLocationInfo() {
+        return (ITmfTimestamp) super.getLocationInfo();
+    }
+
+}
index 0a80b2bf6df2843845e745712e401536c457b631..513fa43ad6a0bd4cca037fda0f0e471e329ed79b 100644 (file)
@@ -32,11 +32,11 @@ import org.eclipse.linuxtools.tmf.core.io.BufferedRandomAccessFile;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 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;
-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;
 
 /**
  * Base class for custom plain text traces.
index ab528a37818588da208156b3c344f4741d66b29e..3b593f8603bd0a6a71a7811e35b309f3b145054b 100644 (file)
@@ -15,8 +15,8 @@ package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;
 import java.util.regex.Matcher;
 
 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 /**
  * Trace context for custom text traces.
index 58b7acae3f86f25e3f37951fc81937b7cb60343d..d120da27fef352e5b02125aaa653ea84a383966f 100644 (file)
@@ -19,10 +19,10 @@ import java.io.RandomAccessFile;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
 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.ui.Activator;
 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;
 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;
@@ -32,11 +32,11 @@ import org.eclipse.linuxtools.tmf.core.io.BufferedRandomAccessFile;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 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;
-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;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
index 310e35503040272bacd1c2cd581d7e780aee4974..55a92f11e9b034b33f74da690be02cba68a6d7af 100644 (file)
@@ -12,8 +12,8 @@
 
 package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;
 
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 /**
  * Trace context for custom XML traces.
index 0626cf3a01a4f8465439e350e453750c6d283777..bafe11740aa9b7526434622e3053fdc9d282a27a 100644 (file)
@@ -90,8 +90,8 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsCache.CachedEvent;
 import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting;
 import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;
index 2570033c2ae9da660971044a97448d8a54ccff0c..84960c55c5d5dc469f1e7a7f63dbf6b595f134f6 100644 (file)
@@ -17,8 +17,8 @@ import java.util.List;
 
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CaretEvent;
 import org.eclipse.swt.custom.CaretListener;
This page took 0.122658 seconds and 5 git commands to generate.